
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Controller · 这是程序员吗</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="xishengcai">
        
        
    
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-disqus/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-prism/prism-base16-ateliersulphurpool.light.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-advanced-emoji/emoji-website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-emphasize/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-katex/katex.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-sectionx/sectionx.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-local-video/video-js.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-terminal/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-versions-select/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    


    

        
    
    
    
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="copy docker config.html" />
    
    
    <link rel="prev" href="command.html" />
    

    
    <link rel="stylesheet" href="../../gitbook/gitbook-plugin-chart/c3/c3.min.css">
    <script src="../../gitbook/gitbook-plugin-chart/c3/d3.min.js"></script>
    <script src="../../gitbook/gitbook-plugin-chart/c3/c3.min.js"></script>
    

    <script src="../../gitbook/gitbook-plugin-graph/d3.min.js"></script>
    <script src="../../gitbook/gitbook-plugin-graph/function-plot.js"></script>    

    
        <link rel="shortcut icon" href='../../favicon.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../../favicon.ico' type="image/x-icon">
    
    
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"repo":"xishengcai/xisheng.blog","types":["star"],"size":"small"};
    </script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://xisheng.vip" target="_blank" class="custom-link">Home</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        <li class="header">Blog</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                        <b>1.1.</b>
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../algorithm/">
            
                <a href="../algorithm/">
            
                    
                        <b>1.2.</b>
                    
                    Algorithm
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../algorithm/heap.html">
            
                <a href="../algorithm/heap.html">
            
                    
                        <b>1.2.1.</b>
                    
                    Heap
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../algorithm/readme.html">
            
                <a href="../algorithm/readme.html">
            
                    
                        <b>1.2.2.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../angular/">
            
                <a href="../angular/">
            
                    
                        <b>1.3.</b>
                    
                    Angular
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../angular/1-start.html">
            
                <a href="../angular/1-start.html">
            
                    
                        <b>1.3.1.</b>
                    
                    Start
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../angular/2-component.html">
            
                <a href="../angular/2-component.html">
            
                    
                        <b>1.3.2.</b>
                    
                    Component
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../angular/3-form.html">
            
                <a href="../angular/3-form.html">
            
                    
                        <b>1.3.3.</b>
                    
                    Form
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../angular/readme.html">
            
                <a href="../angular/readme.html">
            
                    
                        <b>1.3.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../database/">
            
                <a href="../database/">
            
                    
                        <b>1.4.</b>
                    
                    Database
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../database/mongodb.html">
            
                <a href="../database/mongodb.html">
            
                    
                        <b>1.4.1.</b>
                    
                    Mongodb
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../database/readme.html">
            
                <a href="../database/readme.html">
            
                    
                        <b>1.4.2.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../docker/">
            
                <a href="../docker/">
            
                    
                        <b>1.5.</b>
                    
                    Docker
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../docker/CentOS.html">
            
                <a href="../docker/CentOS.html">
            
                    
                        <b>1.5.1.</b>
                    
                    CentOS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../docker/install.html">
            
                <a href="../docker/install.html">
            
                    
                        <b>1.5.2.</b>
                    
                    Install
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../docker/readme.html">
            
                <a href="../docker/readme.html">
            
                    
                        <b>1.5.3.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../docker/官方shell.html">
            
                <a href="../docker/官方shell.html">
            
                    
                        <b>1.5.4.</b>
                    
                    官方Shell
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../golang/">
            
                <a href="../golang/">
            
                    
                        <b>1.6.</b>
                    
                    Golang
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../golang/aop.html">
            
                <a href="../golang/aop.html">
            
                    
                        <b>1.6.1.</b>
                    
                    Aop
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../golang/base/">
            
                <a href="../golang/base/">
            
                    
                        <b>1.6.2.</b>
                    
                    Base
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.2.1" data-path="../golang/base/copy.html">
            
                <a href="../golang/base/copy.html">
            
                    
                        <b>1.6.2.1.</b>
                    
                    Copy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.2" data-path="../golang/base/new_and_make.html">
            
                <a href="../golang/base/new_and_make.html">
            
                    
                        <b>1.6.2.2.</b>
                    
                    New And Make
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.3" data-path="../golang/base/readme.html">
            
                <a href="../golang/base/readme.html">
            
                    
                        <b>1.6.2.3.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.4" data-path="../golang/base/reflect.html">
            
                <a href="../golang/base/reflect.html">
            
                    
                        <b>1.6.2.4.</b>
                    
                    Reflect
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.5" data-path="../golang/base/string.html">
            
                <a href="../golang/base/string.html">
            
                    
                        <b>1.6.2.5.</b>
                    
                    String
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.6" data-path="../golang/base/tag.html">
            
                <a href="../golang/base/tag.html">
            
                    
                        <b>1.6.2.6.</b>
                    
                    Tag
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../golang/clouser.html">
            
                <a href="../golang/clouser.html">
            
                    
                        <b>1.6.3.</b>
                    
                    Clouser
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../golang/err 优雅处理.html">
            
                <a href="../golang/err 优雅处理.html">
            
                    
                        <b>1.6.4.</b>
                    
                    Err 优雅处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../golang/go module 2.html">
            
                <a href="../golang/go module 2.html">
            
                    
                        <b>1.6.5.</b>
                    
                    Go Module 2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../golang/go_mod.html">
            
                <a href="../golang/go_mod.html">
            
                    
                        <b>1.6.6.</b>
                    
                    Go Mod
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../golang/gocraftwork.html">
            
                <a href="../golang/gocraftwork.html">
            
                    
                        <b>1.6.7.</b>
                    
                    Gocraftwork
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../golang/oauth.html">
            
                <a href="../golang/oauth.html">
            
                    
                        <b>1.6.8.</b>
                    
                    Oauth
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../golang/readme.html">
            
                <a href="../golang/readme.html">
            
                    
                        <b>1.6.9.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../golang/swagger.html">
            
                <a href="../golang/swagger.html">
            
                    
                        <b>1.6.10.</b>
                    
                    Swagger
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="../golang/tls.html">
            
                <a href="../golang/tls.html">
            
                    
                        <b>1.6.11.</b>
                    
                    Tls
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.12" >
            
                <span>
            
                    
                        <b>1.6.12.</b>
                    
                    代码走读
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.12.1" data-path="../golang/代码走读/2020.5.26.html">
            
                <a href="../golang/代码走读/2020.5.26.html">
            
                    
                        <b>1.6.12.1.</b>
                    
                    2020.5.26
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.13" data-path="../golang/任务队列/">
            
                <a href="../golang/任务队列/">
            
                    
                        <b>1.6.13.</b>
                    
                    任务队列
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.13.1" data-path="../golang/任务队列/gocraft-worker.html">
            
                <a href="../golang/任务队列/gocraft-worker.html">
            
                    
                        <b>1.6.13.1.</b>
                    
                    Gocraft Worker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.13.2" data-path="../golang/任务队列/readme.html">
            
                <a href="../golang/任务队列/readme.html">
            
                    
                        <b>1.6.13.2.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.14" data-path="../golang/参数校验.html">
            
                <a href="../golang/参数校验.html">
            
                    
                        <b>1.6.14.</b>
                    
                    参数校验
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../istio/">
            
                <a href="../istio/">
            
                    
                        <b>1.7.</b>
                    
                    Istio
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../istio/readme.html">
            
                <a href="../istio/readme.html">
            
                    
                        <b>1.7.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../istio/virtualservice.html">
            
                <a href="../istio/virtualservice.html">
            
                    
                        <b>1.7.2.</b>
                    
                    Virtualservice
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" >
            
                <span>
            
                    
                        <b>1.8.</b>
                    
                    Java
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../java/jvm.html">
            
                <a href="../java/jvm.html">
            
                    
                        <b>1.8.1.</b>
                    
                    Jvm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../java/typescript.html">
            
                <a href="../java/typescript.html">
            
                    
                        <b>1.8.2.</b>
                    
                    Typescript
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="./">
            
                <a href="./">
            
                    
                        <b>1.9.</b>
                    
                    Kubernetes
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="APIService.html">
            
                <a href="APIService.html">
            
                    
                        <b>1.9.1.</b>
                    
                    APIService
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="CAK.html">
            
                <a href="CAK.html">
            
                    
                        <b>1.9.2.</b>
                    
                    CAK
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="Deployment 的实现原理.html">
            
                <a href="Deployment 的实现原理.html">
            
                    
                        <b>1.9.3.</b>
                    
                    Deployment 的实现原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="K8s源码/">
            
                <a href="K8s源码/">
            
                    
                        <b>1.9.4.</b>
                    
                    K8s源码
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.4.1" data-path="K8s源码/calico 源码分析.html">
            
                <a href="K8s源码/calico 源码分析.html">
            
                    
                        <b>1.9.4.1.</b>
                    
                    Calico 源码分析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.2" data-path="K8s源码/garbage collector controller 源码分析.html">
            
                <a href="K8s源码/garbage collector controller 源码分析.html">
            
                    
                        <b>1.9.4.2.</b>
                    
                    Garbage Collector Controller 源码分析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.3" data-path="K8s源码/job.html">
            
                <a href="K8s源码/job.html">
            
                    
                        <b>1.9.4.3.</b>
                    
                    Job
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.4" data-path="K8s源码/kube-proxy-iptables.html">
            
                <a href="K8s源码/kube-proxy-iptables.html">
            
                    
                        <b>1.9.4.4.</b>
                    
                    Kube Proxy Iptables
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.5" data-path="K8s源码/kube-proxy-ipvs.html">
            
                <a href="K8s源码/kube-proxy-ipvs.html">
            
                    
                        <b>1.9.4.5.</b>
                    
                    Kube Proxy Ipvs
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.6" data-path="K8s源码/kube-proxy.html">
            
                <a href="K8s源码/kube-proxy.html">
            
                    
                        <b>1.9.4.6.</b>
                    
                    Kube Proxy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.7" data-path="K8s源码/kubectl-exec.html">
            
                <a href="K8s源码/kubectl-exec.html">
            
                    
                        <b>1.9.4.7.</b>
                    
                    Kubectl Exec
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.8" data-path="K8s源码/kubectl源码阅读1.html">
            
                <a href="K8s源码/kubectl源码阅读1.html">
            
                    
                        <b>1.9.4.8.</b>
                    
                    Kubectl源码阅读1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.9" data-path="K8s源码/kubectl源码阅读2.html">
            
                <a href="K8s源码/kubectl源码阅读2.html">
            
                    
                        <b>1.9.4.9.</b>
                    
                    Kubectl源码阅读2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.10" data-path="K8s源码/readme.html">
            
                <a href="K8s源码/readme.html">
            
                    
                        <b>1.9.4.10.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.11" data-path="K8s源码/schedule.html">
            
                <a href="K8s源码/schedule.html">
            
                    
                        <b>1.9.4.11.</b>
                    
                    Schedule
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.12" data-path="K8s源码/scheme.html">
            
                <a href="K8s源码/scheme.html">
            
                    
                        <b>1.9.4.12.</b>
                    
                    Scheme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.13" data-path="K8s源码/调度队列.html">
            
                <a href="K8s源码/调度队列.html">
            
                    
                        <b>1.9.4.13.</b>
                    
                    调度队列
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.5" data-path="Karmada.html">
            
                <a href="Karmada.html">
            
                    
                        <b>1.9.5.</b>
                    
                    Karmada
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.6" data-path="Pixie.html">
            
                <a href="Pixie.html">
            
                    
                        <b>1.9.6.</b>
                    
                    Pixie
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.7" data-path="admission access.html">
            
                <a href="admission access.html">
            
                    
                        <b>1.9.7.</b>
                    
                    Admission Access
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.8" data-path="ccm.html">
            
                <a href="ccm.html">
            
                    
                        <b>1.9.8.</b>
                    
                    Ccm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.9" data-path="client-go.html">
            
                <a href="client-go.html">
            
                    
                        <b>1.9.9.</b>
                    
                    Client Go
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.10" data-path="command.html">
            
                <a href="command.html">
            
                    
                        <b>1.9.10.</b>
                    
                    Command
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.9.11" data-path="controller.html">
            
                <a href="controller.html">
            
                    
                        <b>1.9.11.</b>
                    
                    Controller
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.12" data-path="copy docker config.html">
            
                <a href="copy docker config.html">
            
                    
                        <b>1.9.12.</b>
                    
                    Copy Docker Config
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.13" data-path="etcd-operation.html">
            
                <a href="etcd-operation.html">
            
                    
                        <b>1.9.13.</b>
                    
                    Etcd Operation
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.14" data-path="gc.html">
            
                <a href="gc.html">
            
                    
                        <b>1.9.14.</b>
                    
                    Gc
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.15" data-path="helm chart.html">
            
                <a href="helm chart.html">
            
                    
                        <b>1.9.15.</b>
                    
                    Helm Chart
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.16" data-path="helm.html">
            
                <a href="helm.html">
            
                    
                        <b>1.9.16.</b>
                    
                    Helm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.17" >
            
                <span>
            
                    
                        <b>1.9.17.</b>
                    
                    Helm
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.17.1" data-path="helm/charts.html">
            
                <a href="helm/charts.html">
            
                    
                        <b>1.9.17.1.</b>
                    
                    Charts
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.17.2" data-path="helm/helm 钩子函数.html">
            
                <a href="helm/helm 钩子函数.html">
            
                    
                        <b>1.9.17.2.</b>
                    
                    Helm 钩子函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.17.3" data-path="helm/helm-operator.html">
            
                <a href="helm/helm-operator.html">
            
                    
                        <b>1.9.17.3.</b>
                    
                    Helm Operator
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.17.4" data-path="helm/文档查询.html">
            
                <a href="helm/文档查询.html">
            
                    
                        <b>1.9.17.4.</b>
                    
                    文档查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.17.5" data-path="helm/语法.html">
            
                <a href="helm/语法.html">
            
                    
                        <b>1.9.17.5.</b>
                    
                    语法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.18" data-path="install.html">
            
                <a href="install.html">
            
                    
                        <b>1.9.18.</b>
                    
                    Install
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.19" data-path="istio-inject.html">
            
                <a href="istio-inject.html">
            
                    
                        <b>1.9.19.</b>
                    
                    Istio Inject
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.20" >
            
                <span>
            
                    
                        <b>1.9.20.</b>
                    
                    KubeEdge
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.21" data-path="kuber-apiserver-flag.html">
            
                <a href="kuber-apiserver-flag.html">
            
                    
                        <b>1.9.21.</b>
                    
                    Kuber Apiserver Flag
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.22" data-path="kubernetes-client.html">
            
                <a href="kubernetes-client.html">
            
                    
                        <b>1.9.22.</b>
                    
                    Kubernetes Client
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.23" data-path="kubernetes灾备.html">
            
                <a href="kubernetes灾备.html">
            
                    
                        <b>1.9.23.</b>
                    
                    Kubernetes灾备
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.24" data-path="kubesphere/">
            
                <a href="kubesphere/">
            
                    
                        <b>1.9.24.</b>
                    
                    Kubesphere
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.24.1" data-path="kubesphere/helm.html">
            
                <a href="kubesphere/helm.html">
            
                    
                        <b>1.9.24.1.</b>
                    
                    Helm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.24.2" data-path="kubesphere/readme.html">
            
                <a href="kubesphere/readme.html">
            
                    
                        <b>1.9.24.2.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.25" data-path="kubevela/">
            
                <a href="kubevela/">
            
                    
                        <b>1.9.25.</b>
                    
                    Kubevela
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.25.1" data-path="kubevela/KubeVela 功能.html">
            
                <a href="kubevela/KubeVela 功能.html">
            
                    
                        <b>1.9.25.1.</b>
                    
                    KubeVela 功能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.2" data-path="kubevela/cue.html">
            
                <a href="kubevela/cue.html">
            
                    
                        <b>1.9.25.2.</b>
                    
                    Cue
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.3" data-path="kubevela/oam.html">
            
                <a href="kubevela/oam.html">
            
                    
                        <b>1.9.25.3.</b>
                    
                    Oam
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.4" data-path="kubevela/readme.html">
            
                <a href="kubevela/readme.html">
            
                    
                        <b>1.9.25.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.5" data-path="kubevela/rollout design.html">
            
                <a href="kubevela/rollout design.html">
            
                    
                        <b>1.9.25.5.</b>
                    
                    Rollout Design
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.6" data-path="kubevela/vela run.html">
            
                <a href="kubevela/vela run.html">
            
                    
                        <b>1.9.25.6.</b>
                    
                    Vela Run
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.7" data-path="kubevela/vela up.html">
            
                <a href="kubevela/vela up.html">
            
                    
                        <b>1.9.25.7.</b>
                    
                    Vela Up
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.8" data-path="kubevela/vela-cluster.html">
            
                <a href="kubevela/vela-cluster.html">
            
                    
                        <b>1.9.25.8.</b>
                    
                    Vela Cluster
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.9" data-path="kubevela/vela-helm.html">
            
                <a href="kubevela/vela-helm.html">
            
                    
                        <b>1.9.25.9.</b>
                    
                    Vela Helm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.10" data-path="kubevela/vela-pk-oam.html">
            
                <a href="kubevela/vela-pk-oam.html">
            
                    
                        <b>1.9.25.10.</b>
                    
                    Vela Pk Oam
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.26" data-path="mk-cert.html">
            
                <a href="mk-cert.html">
            
                    
                        <b>1.9.26.</b>
                    
                    Mk Cert
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.27" data-path="open_swagger-ui.html">
            
                <a href="open_swagger-ui.html">
            
                    
                        <b>1.9.27.</b>
                    
                    Open Swagger Ui
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.28" data-path="readme.html">
            
                <a href="readme.html">
            
                    
                        <b>1.9.28.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29" data-path="task/">
            
                <a href="task/">
            
                    
                        <b>1.9.29.</b>
                    
                    Task
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.29.1" data-path="task/HPA.html">
            
                <a href="task/HPA.html">
            
                    
                        <b>1.9.29.1.</b>
                    
                    HPA
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.2" data-path="task/kubectl patch.html">
            
                <a href="task/kubectl patch.html">
            
                    
                        <b>1.9.29.2.</b>
                    
                    Kubectl Patch
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.3" data-path="task/pod 信息注入.html">
            
                <a href="task/pod 信息注入.html">
            
                    
                        <b>1.9.29.3.</b>
                    
                    Pod 信息注入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.4" data-path="task/pod 垂直扩缩容.html">
            
                <a href="task/pod 垂直扩缩容.html">
            
                    
                        <b>1.9.29.4.</b>
                    
                    Pod 垂直扩缩容
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.5" data-path="task/readme.html">
            
                <a href="task/readme.html">
            
                    
                        <b>1.9.29.5.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.6" data-path="task/server-side-apply.html">
            
                <a href="task/server-side-apply.html">
            
                    
                        <b>1.9.29.6.</b>
                    
                    Server Side Apply
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.7" data-path="task/准入控制.html">
            
                <a href="task/准入控制.html">
            
                    
                        <b>1.9.29.7.</b>
                    
                    准入控制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.8" data-path="task/聚合api.html">
            
                <a href="task/聚合api.html">
            
                    
                        <b>1.9.29.8.</b>
                    
                    聚合Api
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.9" data-path="task/资源预留配置.html">
            
                <a href="task/资源预留配置.html">
            
                    
                        <b>1.9.29.9.</b>
                    
                    资源预留配置
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.30" data-path="webhook.html">
            
                <a href="webhook.html">
            
                    
                        <b>1.9.30.</b>
                    
                    Webhook
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.31" data-path="一致性认证.html">
            
                <a href="一致性认证.html">
            
                    
                        <b>1.9.31.</b>
                    
                    一致性认证
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.32" data-path="专利名词.html">
            
                <a href="专利名词.html">
            
                    
                        <b>1.9.32.</b>
                    
                    专利名词
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.33" data-path="删除namespace.html">
            
                <a href="删除namespace.html">
            
                    
                        <b>1.9.33.</b>
                    
                    删除Namespace
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.34" data-path="简化多集群.html">
            
                <a href="简化多集群.html">
            
                    
                        <b>1.9.34.</b>
                    
                    简化多集群
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.35" data-path="网络插件/">
            
                <a href="网络插件/">
            
                    
                        <b>1.9.35.</b>
                    
                    网络插件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.35.1" data-path="网络插件/calico.html">
            
                <a href="网络插件/calico.html">
            
                    
                        <b>1.9.35.1.</b>
                    
                    Calico
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.35.2" data-path="网络插件/cilium.html">
            
                <a href="网络插件/cilium.html">
            
                    
                        <b>1.9.35.2.</b>
                    
                    Cilium
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.35.3" data-path="网络插件/ebpf.html">
            
                <a href="网络插件/ebpf.html">
            
                    
                        <b>1.9.35.3.</b>
                    
                    Ebpf
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.35.4" data-path="网络插件/readme.html">
            
                <a href="网络插件/readme.html">
            
                    
                        <b>1.9.35.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.36" data-path="镜像/">
            
                <a href="镜像/">
            
                    
                        <b>1.9.36.</b>
                    
                    镜像
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.36.1" data-path="镜像/Containerd Stargz Snapshotter.html">
            
                <a href="镜像/Containerd Stargz Snapshotter.html">
            
                    
                        <b>1.9.36.1.</b>
                    
                    Containerd Stargz Snapshotter
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.36.2" data-path="镜像/OCI.html">
            
                <a href="镜像/OCI.html">
            
                    
                        <b>1.9.36.2.</b>
                    
                    OCI
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.36.3" data-path="镜像/harbor/">
            
                <a href="镜像/harbor/">
            
                    
                        <b>1.9.36.3.</b>
                    
                    Harbor
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.36.3.1" data-path="镜像/harbor/readme.html">
            
                <a href="镜像/harbor/readme.html">
            
                    
                        <b>1.9.36.3.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.36.4" data-path="镜像/readme.html">
            
                <a href="镜像/readme.html">
            
                    
                        <b>1.9.36.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.36.5" data-path="镜像/自动构建镜像.html">
            
                <a href="镜像/自动构建镜像.html">
            
                    
                        <b>1.9.36.5.</b>
                    
                    自动构建镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.36.6" data-path="镜像/镜像加速方案.html">
            
                <a href="镜像/镜像加速方案.html">
            
                    
                        <b>1.9.36.6.</b>
                    
                    镜像加速方案
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.36.7" data-path="镜像/镜像延迟加载技术解析.html">
            
                <a href="镜像/镜像延迟加载技术解析.html">
            
                    
                        <b>1.9.36.7.</b>
                    
                    镜像延迟加载技术解析
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../math/">
            
                <a href="../math/">
            
                    
                        <b>1.10.</b>
                    
                    Math
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../math/readme.html">
            
                <a href="../math/readme.html">
            
                    
                        <b>1.10.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../math/泊松分布.html">
            
                <a href="../math/泊松分布.html">
            
                    
                        <b>1.10.2.</b>
                    
                    泊松分布
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../效率/">
            
                <a href="../效率/">
            
                    
                        <b>1.11.</b>
                    
                    效率
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../效率/cat.html">
            
                <a href="../效率/cat.html">
            
                    
                        <b>1.11.1.</b>
                    
                    Cat
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../效率/docker volume clean.html">
            
                <a href="../效率/docker volume clean.html">
            
                    
                        <b>1.11.2.</b>
                    
                    Docker Volume Clean
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../效率/git book.html">
            
                <a href="../效率/git book.html">
            
                    
                        <b>1.11.3.</b>
                    
                    Git Book
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../效率/git.html">
            
                <a href="../效率/git.html">
            
                    
                        <b>1.11.4.</b>
                    
                    Git
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../效率/linux command.html">
            
                <a href="../效率/linux command.html">
            
                    
                        <b>1.11.5.</b>
                    
                    Linux Command
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.6" data-path="../效率/linux 内核.html">
            
                <a href="../效率/linux 内核.html">
            
                    
                        <b>1.11.6.</b>
                    
                    Linux 内核
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.7" data-path="../效率/macos path.html">
            
                <a href="../效率/macos path.html">
            
                    
                        <b>1.11.7.</b>
                    
                    Macos Path
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.8" data-path="../效率/nfs.html">
            
                <a href="../效率/nfs.html">
            
                    
                        <b>1.11.8.</b>
                    
                    Nfs
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.9" data-path="../效率/nginx.html">
            
                <a href="../效率/nginx.html">
            
                    
                        <b>1.11.9.</b>
                    
                    Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.10" data-path="../效率/nginx2.html">
            
                <a href="../效率/nginx2.html">
            
                    
                        <b>1.11.10.</b>
                    
                    Nginx2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.11" data-path="../效率/oauth2.html">
            
                <a href="../效率/oauth2.html">
            
                    
                        <b>1.11.11.</b>
                    
                    Oauth2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.12" data-path="../效率/ovftool.html">
            
                <a href="../效率/ovftool.html">
            
                    
                        <b>1.11.12.</b>
                    
                    Ovftool
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.13" data-path="../效率/readme.html">
            
                <a href="../效率/readme.html">
            
                    
                        <b>1.11.13.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.14" data-path="../效率/sed.html">
            
                <a href="../效率/sed.html">
            
                    
                        <b>1.11.14.</b>
                    
                    Sed
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.15" data-path="../效率/shell_judge.html">
            
                <a href="../效率/shell_judge.html">
            
                    
                        <b>1.11.15.</b>
                    
                    Shell Judge
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.16" data-path="../效率/sshpass.html">
            
                <a href="../效率/sshpass.html">
            
                    
                        <b>1.11.16.</b>
                    
                    Sshpass
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.17" data-path="../效率/telepresence.html">
            
                <a href="../效率/telepresence.html">
            
                    
                        <b>1.11.17.</b>
                    
                    Telepresence
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.18" data-path="../效率/typora.html">
            
                <a href="../效率/typora.html">
            
                    
                        <b>1.11.18.</b>
                    
                    Typora
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.19" data-path="../效率/url encode.html">
            
                <a href="../效率/url encode.html">
            
                    
                        <b>1.11.19.</b>
                    
                    Url Encode
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.20" data-path="../效率/vim.html">
            
                <a href="../效率/vim.html">
            
                    
                        <b>1.11.20.</b>
                    
                    Vim
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.21" data-path="../效率/yum.html">
            
                <a href="../效率/yum.html">
            
                    
                        <b>1.11.21.</b>
                    
                    Yum
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.22" data-path="../效率/内网穿透.html">
            
                <a href="../效率/内网穿透.html">
            
                    
                        <b>1.11.22.</b>
                    
                    内网穿透
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.23" data-path="../效率/科学上网.html">
            
                <a href="../效率/科学上网.html">
            
                    
                        <b>1.11.23.</b>
                    
                    科学上网
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.24" data-path="../效率/证书制作.html">
            
                <a href="../效率/证书制作.html">
            
                    
                        <b>1.11.24.</b>
                    
                    证书制作
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" >
            
                <span>
            
                    
                        <b>1.12.</b>
                    
                    杂谈
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../杂谈/论好文章和烂文章.html">
            
                <a href="../杂谈/论好文章和烂文章.html">
            
                    
                        <b>1.12.1.</b>
                    
                    论好文章和烂文章
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../测试/">
            
                <a href="../测试/">
            
                    
                        <b>1.13.</b>
                    
                    测试
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../测试/ginkgo/">
            
                <a href="../测试/ginkgo/">
            
                    
                        <b>1.13.1.</b>
                    
                    Ginkgo
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1.1" data-path="../测试/ginkgo/ginkgo.html">
            
                <a href="../测试/ginkgo/ginkgo.html">
            
                    
                        <b>1.13.1.1.</b>
                    
                    Ginkgo
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.1.2" data-path="../测试/ginkgo/ginkgo_cmd.html">
            
                <a href="../测试/ginkgo/ginkgo_cmd.html">
            
                    
                        <b>1.13.1.2.</b>
                    
                    Ginkgo Cmd
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.1.3" data-path="../测试/ginkgo/readme.html">
            
                <a href="../测试/ginkgo/readme.html">
            
                    
                        <b>1.13.1.3.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../测试/golang-test.html">
            
                <a href="../测试/golang-test.html">
            
                    
                        <b>1.13.2.</b>
                    
                    Golang Test
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../测试/http测试.html">
            
                <a href="../测试/http测试.html">
            
                    
                        <b>1.13.3.</b>
                    
                    Http测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.4" data-path="../测试/readme.html">
            
                <a href="../测试/readme.html">
            
                    
                        <b>1.13.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.5" data-path="../测试/其他功能.html">
            
                <a href="../测试/其他功能.html">
            
                    
                        <b>1.13.5.</b>
                    
                    其他功能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.6" data-path="../测试/单元测试.html">
            
                <a href="../测试/单元测试.html">
            
                    
                        <b>1.13.6.</b>
                    
                    单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.7" data-path="../测试/单元测试2.html">
            
                <a href="../测试/单元测试2.html">
            
                    
                        <b>1.13.7.</b>
                    
                    单元测试2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.8" data-path="../测试/基准测试.html">
            
                <a href="../测试/基准测试.html">
            
                    
                        <b>1.13.8.</b>
                    
                    基准测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.9" data-path="../测试/子测试与子基准测试.html">
            
                <a href="../测试/子测试与子基准测试.html">
            
                    
                        <b>1.13.9.</b>
                    
                    子测试与子基准测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.10" data-path="../测试/并行测试.html">
            
                <a href="../测试/并行测试.html">
            
                    
                        <b>1.13.10.</b>
                    
                    并行测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.11" data-path="../测试/质量检查/">
            
                <a href="../测试/质量检查/">
            
                    
                        <b>1.13.11.</b>
                    
                    质量检查
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.11.1" data-path="../测试/质量检查/Sonar.html">
            
                <a href="../测试/质量检查/Sonar.html">
            
                    
                        <b>1.13.11.1.</b>
                    
                    Sonar
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.11.2" data-path="../测试/质量检查/go_lint.html">
            
                <a href="../测试/质量检查/go_lint.html">
            
                    
                        <b>1.13.11.2.</b>
                    
                    Go Lint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.11.3" data-path="../测试/质量检查/readme.html">
            
                <a href="../测试/质量检查/readme.html">
            
                    
                        <b>1.13.11.3.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../规范/">
            
                <a href="../规范/">
            
                    
                        <b>1.14.</b>
                    
                    规范
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="../规范/CodeReviewComments.html">
            
                <a href="../规范/CodeReviewComments.html">
            
                    
                        <b>1.14.1.</b>
                    
                    CodeReviewComments
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="../规范/git规范.html">
            
                <a href="../规范/git规范.html">
            
                    
                        <b>1.14.2.</b>
                    
                    Git规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.3" data-path="../规范/golang 代码规范.html">
            
                <a href="../规范/golang 代码规范.html">
            
                    
                        <b>1.14.3.</b>
                    
                    Golang 代码规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.4" data-path="../规范/readme.html">
            
                <a href="../规范/readme.html">
            
                    
                        <b>1.14.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.5" data-path="../规范/代码走读.html">
            
                <a href="../规范/代码走读.html">
            
                    
                        <b>1.14.5.</b>
                    
                    代码走读
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../设计模式/">
            
                <a href="../设计模式/">
            
                    
                        <b>1.15.</b>
                    
                    设计模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../设计模式/readme.html">
            
                <a href="../设计模式/readme.html">
            
                    
                        <b>1.15.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2" data-path="../设计模式/创建模型/">
            
                <a href="../设计模式/创建模型/">
            
                    
                        <b>1.15.2.</b>
                    
                    创建模型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.2.1" data-path="../设计模式/创建模型/readme.html">
            
                <a href="../设计模式/创建模型/readme.html">
            
                    
                        <b>1.15.2.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.2" data-path="../设计模式/创建模型/创建者模型.html">
            
                <a href="../设计模式/创建模型/创建者模型.html">
            
                    
                        <b>1.15.2.2.</b>
                    
                    创建者模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.3" data-path="../设计模式/创建模型/单例模式.html">
            
                <a href="../设计模式/创建模型/单例模式.html">
            
                    
                        <b>1.15.2.3.</b>
                    
                    单例模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.4" data-path="../设计模式/创建模型/原型模式.html">
            
                <a href="../设计模式/创建模型/原型模式.html">
            
                    
                        <b>1.15.2.4.</b>
                    
                    原型模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.5" data-path="../设计模式/创建模型/工厂方法.html">
            
                <a href="../设计模式/创建模型/工厂方法.html">
            
                    
                        <b>1.15.2.5.</b>
                    
                    工厂方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.6" data-path="../设计模式/创建模型/抽象工厂.html">
            
                <a href="../设计模式/创建模型/抽象工厂.html">
            
                    
                        <b>1.15.2.6.</b>
                    
                    抽象工厂
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.7" data-path="../设计模式/创建模型/简单工厂.html">
            
                <a href="../设计模式/创建模型/简单工厂.html">
            
                    
                        <b>1.15.2.7.</b>
                    
                    简单工厂
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15.3" data-path="../设计模式/结构型模型/">
            
                <a href="../设计模式/结构型模型/">
            
                    
                        <b>1.15.3.</b>
                    
                    结构型模型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.3.1" data-path="../设计模式/结构型模型/readme.html">
            
                <a href="../设计模式/结构型模型/readme.html">
            
                    
                        <b>1.15.3.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.2" data-path="../设计模式/结构型模型/享元模式.html">
            
                <a href="../设计模式/结构型模型/享元模式.html">
            
                    
                        <b>1.15.3.2.</b>
                    
                    享元模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.3" data-path="../设计模式/结构型模型/代理模式.html">
            
                <a href="../设计模式/结构型模型/代理模式.html">
            
                    
                        <b>1.15.3.3.</b>
                    
                    代理模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.4" data-path="../设计模式/结构型模型/外观模式.html">
            
                <a href="../设计模式/结构型模型/外观模式.html">
            
                    
                        <b>1.15.3.4.</b>
                    
                    外观模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.5" data-path="../设计模式/结构型模型/桥模式.html">
            
                <a href="../设计模式/结构型模型/桥模式.html">
            
                    
                        <b>1.15.3.5.</b>
                    
                    桥模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.6" data-path="../设计模式/结构型模型/组合模式.html">
            
                <a href="../设计模式/结构型模型/组合模式.html">
            
                    
                        <b>1.15.3.6.</b>
                    
                    组合模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.7" data-path="../设计模式/结构型模型/装饰模式.html">
            
                <a href="../设计模式/结构型模型/装饰模式.html">
            
                    
                        <b>1.15.3.7.</b>
                    
                    装饰模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.8" data-path="../设计模式/结构型模型/适配器模式.html">
            
                <a href="../设计模式/结构型模型/适配器模式.html">
            
                    
                        <b>1.15.3.8.</b>
                    
                    适配器模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15.4" data-path="../设计模式/行为型模型/">
            
                <a href="../设计模式/行为型模型/">
            
                    
                        <b>1.15.4.</b>
                    
                    行为型模型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.4.1" data-path="../设计模式/行为型模型/readme.html">
            
                <a href="../设计模式/行为型模型/readme.html">
            
                    
                        <b>1.15.4.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.2" data-path="../设计模式/行为型模型/中介者模式.html">
            
                <a href="../设计模式/行为型模型/中介者模式.html">
            
                    
                        <b>1.15.4.2.</b>
                    
                    中介者模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.3" data-path="../设计模式/行为型模型/命令模式.html">
            
                <a href="../设计模式/行为型模型/命令模式.html">
            
                    
                        <b>1.15.4.3.</b>
                    
                    命令模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.4" data-path="../设计模式/行为型模型/备忘录模式.html">
            
                <a href="../设计模式/行为型模型/备忘录模式.html">
            
                    
                        <b>1.15.4.4.</b>
                    
                    备忘录模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.5" data-path="../设计模式/行为型模型/模板方法模式.html">
            
                <a href="../设计模式/行为型模型/模板方法模式.html">
            
                    
                        <b>1.15.4.5.</b>
                    
                    模板方法模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.6" data-path="../设计模式/行为型模型/状态模式.html">
            
                <a href="../设计模式/行为型模型/状态模式.html">
            
                    
                        <b>1.15.4.6.</b>
                    
                    状态模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.7" data-path="../设计模式/行为型模型/策略模式.html">
            
                <a href="../设计模式/行为型模型/策略模式.html">
            
                    
                        <b>1.15.4.7.</b>
                    
                    策略模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.8" data-path="../设计模式/行为型模型/职责链模式.html">
            
                <a href="../设计模式/行为型模型/职责链模式.html">
            
                    
                        <b>1.15.4.8.</b>
                    
                    职责链模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.9" data-path="../设计模式/行为型模型/观察者模式.html">
            
                <a href="../设计模式/行为型模型/观察者模式.html">
            
                    
                        <b>1.15.4.9.</b>
                    
                    观察者模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.10" data-path="../设计模式/行为型模型/解释器模式.html">
            
                <a href="../设计模式/行为型模型/解释器模式.html">
            
                    
                        <b>1.15.4.10.</b>
                    
                    解释器模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.11" data-path="../设计模式/行为型模型/访问者模式.html">
            
                <a href="../设计模式/行为型模型/访问者模式.html">
            
                    
                        <b>1.15.4.11.</b>
                    
                    访问者模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.12" data-path="../设计模式/行为型模型/迭代器模式.html">
            
                <a href="../设计模式/行为型模型/迭代器模式.html">
            
                    
                        <b>1.15.4.12.</b>
                    
                    迭代器模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >Controller</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="k8s-custom-resource-definition"><a name="k8s-custom-resource-definition" class="anchor-navigation-ex-anchor" href="#k8s-custom-resource-definition"><i class="fa fa-link" aria-hidden="true"></i></a>k8s: Custom Resource Definition</h2>
<p>Custom Resource Definition &#x662F;kubernetes&#x7684;&#x8D44;&#x6E90;&#x6269;&#x5C55;&#x65B9;&#x5F0F;, &#x7B80;&#x79F0;CRD</p>
<h3 id="1-sample-controller-&#x5F00;&#x6E90;&#x6837;&#x677F;&#x9879;&#x76EE;"><a name="1-sample-controller-&#x5F00;&#x6E90;&#x6837;&#x677F;&#x9879;&#x76EE;" class="anchor-navigation-ex-anchor" href="#1-sample-controller-&#x5F00;&#x6E90;&#x6837;&#x677F;&#x9879;&#x76EE;"><i class="fa fa-link" aria-hidden="true"></i></a>1. sample-controller &#x5F00;&#x6E90;&#x6837;&#x677F;&#x9879;&#x76EE;</h3>
<p>sample-controller &#x662F; kubernetes &#x5B98;&#x65B9;&#x63D0;&#x4F9B;&#x7684; CRD Controller &#x6837;&#x4F8B;&#x5B9E;&#x73B0;</p>
<p><a href="https://github.com/kubernetes/sample-controller" target="_blank">sample-controller</a></p>
<h3 id="2-&#x4F7F;&#x7528;client-go&#x5305;&#x8BBF;&#x95EE;kubernetes-crd"><a name="2-&#x4F7F;&#x7528;client-go&#x5305;&#x8BBF;&#x95EE;kubernetes-crd" class="anchor-navigation-ex-anchor" href="#2-&#x4F7F;&#x7528;client-go&#x5305;&#x8BBF;&#x95EE;kubernetes-crd"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x4F7F;&#x7528;client-go&#x5305;&#x8BBF;&#x95EE;Kubernetes CRD</h3>
<h4 id="21-create-crd"><a name="21-create-crd" class="anchor-navigation-ex-anchor" href="#21-create-crd"><i class="fa fa-link" aria-hidden="true"></i></a>2.1 create CRD</h4>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> <span class="token string">&quot;apiextensions.k8s.io/v1beta1&quot;</span>
<span class="token key atrule">kind</span><span class="token punctuation">:</span> <span class="token string">&quot;CustomResourceDefinition&quot;</span>
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">name</span><span class="token punctuation">:</span> <span class="token string">&quot;projects.example.sealyun.com&quot;</span>
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">group</span><span class="token punctuation">:</span> <span class="token string">&quot;example.sealyun.com&quot;</span>
  <span class="token key atrule">version</span><span class="token punctuation">:</span> <span class="token string">&quot;v1alpha1&quot;</span>
  <span class="token key atrule">scope</span><span class="token punctuation">:</span> <span class="token string">&quot;Namespaced&quot;</span>
  <span class="token key atrule">names</span><span class="token punctuation">:</span>
    <span class="token key atrule">plural</span><span class="token punctuation">:</span> <span class="token string">&quot;projects&quot;</span>
    <span class="token key atrule">singular</span><span class="token punctuation">:</span> <span class="token string">&quot;project&quot;</span>
    <span class="token key atrule">kind</span><span class="token punctuation">:</span> <span class="token string">&quot;Project&quot;</span>
  <span class="token key atrule">validation</span><span class="token punctuation">:</span>
    <span class="token key atrule">openAPIV3Schema</span><span class="token punctuation">:</span>
      <span class="token key atrule">required</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">&quot;spec&quot;</span><span class="token punctuation">]</span>
      <span class="token key atrule">properties</span><span class="token punctuation">:</span>
        <span class="token key atrule">spec</span><span class="token punctuation">:</span>
          <span class="token key atrule">required</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">&quot;replicas&quot;</span><span class="token punctuation">]</span>
          <span class="token key atrule">properties</span><span class="token punctuation">:</span>
            <span class="token key atrule">replicas</span><span class="token punctuation">:</span>
              <span class="token key atrule">type</span><span class="token punctuation">:</span> <span class="token string">&quot;integer&quot;</span>
              <span class="token key atrule">minimum</span><span class="token punctuation">:</span> <span class="token number">1</span>
</code></pre>
<h4 id="22-create-golang-client"><a name="22-create-golang-client" class="anchor-navigation-ex-anchor" href="#22-create-golang-client"><i class="fa fa-link" aria-hidden="true"></i></a>2.2 create golang client</h4>
<ul>
<li>define type</li>
<li>define DeepCopy Method<blockquote>
<ul>
<li>Kubernetes API&#xFF08;&#x5728;&#x672C;&#x4F8B;&#x4E2D;&#x4E3A;Project&#x548C;ProjectList&#xFF09;&#x63D0;&#x4F9B;&#x7684;&#x6BCF;&#x79CD;&#x7C7B;&#x578B;&#x90FD;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x8BE5;k8s.io/apimachinery/pkg/runtime.Object&#x63A5;&#x53E3;.
&#x8BE5;&#x63A5;&#x53E3;&#x5B9A;&#x4E49;&#x4E86;&#x4E24;&#x79CD;&#x65B9;&#x6CD5;GetObjectKind()&#x548C;DeepCopyObject()&#x3002;&#x7B2C;&#x4E00;&#x79CD;&#x65B9;&#x6CD5;&#x5DF2;&#x7ECF;&#x7531;&#x5D4C;&#x5165;&#x5F0F;metav1.TypeMeta&#x7ED3;&#x6784;&#x63D0;&#x4F9B;; &#x7B2C;&#x4E8C;&#x4E2A;&#x4F60;&#x5FC5;&#x987B;&#x81EA;&#x5DF1;&#x5B9E;&#x73B0;&#x3002;</li>
</ul>
</blockquote>
</li>
<li>registry type
  schema.GroupVersion
  runtime.NewSchemeBuilder(addKnownTypes)
  SchemeBuilder.AddToScheme</li>
</ul>
<h3 id="3-write-your-customer-controller"><a name="3-write-your-customer-controller" class="anchor-navigation-ex-anchor" href="#3-write-your-customer-controller"><i class="fa fa-link" aria-hidden="true"></i></a>3. Write your customer controller</h3>
<p><img src="http://xisheng.vip/images/clinet-go.jpg" alt="client-go"></p>
<p>&#x6CE8;&#x610F;: &#x8FD9;&#x5F20;&#x56FE;&#x5206;&#x4E3A;&#x4E24;&#x90E8;&#x5206;,&#x9EC4;&#x8272;&#x56FE;&#x6807;&#x662F;&#x5F00;&#x53D1;&#x8005;&#x9700;&#x8981;&#x81EA;&#x884C;&#x5F00;&#x53D1;&#x7684;&#x90E8;&#x5206;&#xFF0C;&#x800C;&#x5176;&#x5B83;&#x7684;&#x90E8;&#x5206;&#x662F;client-go&#x5DF2;&#x7ECF;&#x63D0;&#x4F9B;&#x7684;&#xFF0C;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x5373;&#x53EF;&#x3002;</p>
<ol>
<li><p>&#x901A;&#x8FC7;controller&#x4E2D;&#x7684;Reflector&#x6765;&#x5B9E;&#x73B0;&#x76D1;&#x542C;&#xFF0C;&#x5B83;&#x901A;&#x8FC7;kubernetes&#x7684;List/Watch&#x673A;&#x5236;&#x5C06;&#x5F97;&#x5230;&#x4E8B;&#x4EF6;(Object)&#x5199;&#x5165;&#x5230;Stroe(Delta FIFO)&#x4E2D;&#xFF0C;
&#x540E;&#x7EED;&#x4F1A;&#x57FA;&#x4E8E;&#x8BE5;Delta FIFO&#x5B9E;&#x73B0;&#x5B8C;&#x5168;&#x6309;&#x4E8B;&#x4EF6;&#x53D1;&#x751F;&#x7684;&#x987A;&#x5E8F;&#x8FDB;&#x884C;&#x5206;&#x53D1;&#x5904;&#x7406;&#x3002;</p>
</li>
<li><p>&#x7531;Reflector&#x751F;&#x4EA7;&#x7684;&#x4E8B;&#x4EF6;&#x6700;&#x7EC8;&#x7531;processor&#x6D88;&#x8D39;&#x3002;processor&#x901A;&#x8FC7;POP&#x961F;&#x5217;(Delta FIFO)&#x91CC;&#x7684;&#x4E8B;&#x4EF6;&#xFF0C;&#x66F4;&#x65B0;&#x672C;&#x5730;&#x7684;informer indexer&#x7F13;&#x5B58;&#xFF0C;
&#x540C;&#x65F6;&#x5C06;&#x4E8B;&#x4EF6;distribute&#x7ED9;&#x6240;&#x6709;&#x7684;listener&#x3002;</p>
</li>
<li><p>processer&#x7684;listener&#x7531;&#x5916;&#x90E8;&#x901A;&#x8FC7;AddEventHandler&#x6CE8;&#x518C;&#xFF0C;&#x6BCF;&#x4E2A;listener&#x63D0;&#x4F9B;AddFunc, UpdateFunc, DeleteFunc&#x65B9;&#x6CD5;&#x3002;l
istener&#x5185;&#x90E8;&#x7684;&#x5B9E;&#x73B0;&#x52A0;&#x4E86;&#x4E00;&#x5C42;&#x7F13;&#x5B58;&#xFF0C;&#x7528;&#x4E8E;&#x5B58;&#x653E;pendingNotification&#x3002;listener&#x6700;&#x7EC8;&#x5B9E;&#x73B0;&#x4E86;&#x4E8B;&#x4EF6;&#x7684;&#x5206;&#x53D1;&#xFF0C;&#x4E8B;&#x4EF6;&#x6700;&#x7EC8;&#x88AB;&#x6CE8;&#x518C;&#x7684;handler&#x5904;&#x7406;&#x3002;</p>
</li>
<li><p>&#x6CE8;&#x518C;&#x7684;handler&#x53EF;&#x4EE5;&#x6839;&#x636E;&#x4E8B;&#x4EF6;&#x7684;&#x7C7B;&#x578B;ADD,UPDATE,DELETE&#xFF0C;&#x5C06;&#x8BE5;&#x4E8B;&#x4EF6;&#x7684;key(&#x683C;&#x5F0F;: namespace/resource_name)Enqueue&#x5230;client-go
&#x63D0;&#x4F9B;&#x7684;Workqueue&#x961F;&#x5217;&#x4E2D;&#x3002;</p>
</li>
<li><p>&#x5F00;&#x53D1;&#x8005;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x81EA;&#x5DF1;&#x7684;controller syncHandler(&#x5C31;&#x662F;&#x81EA;&#x5DF1;&#x7684;&#x6838;&#x5FC3;&#x903B;&#x8F91;)&#xFF0C;&#x4ECE;Workqueue&#x4E2D;&#x83B7;&#x53D6;key&#xFF0C;&#x5E76;&#x901A;&#x8FC7;&#x8FD9;&#x4E2A;key&#x89E3;&#x6790;&#x51FA;namespace&#x548C;
resource_name&#x53BB;&#x8C03;&#x7528;Lister&#x4ECE;indexer&#x4E2D;&#x83B7;&#x53D6;&#x8BE5;key&#x5BF9;&#x5E94;&#x7684;&#x76F8;&#x5E94;&#x7684;&#x5143;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x540E;&#x7EED;&#x7684;&#x903B;&#x8F91;&#x5904;&#x7406;&#x3002;</p>
</li>
</ol>
<p>&#x4E0A;&#x9762;&#x5C31;&#x662F;&#x5F00;&#x53D1;&#x8005;&#x60F3;&#x8981;&#x5199;&#x4E00;&#x4E2A;controller(&#x6216;&#x8005;&#x6709;&#x7684;&#x4EBA;&#x4E5F;&#x53EB;operator)&#x7684;&#x4E00;&#x4E2A;&#x6574;&#x4F53;&#x7684;&#x6D41;&#x7A0B;&#x3002;</p>
<h4 id="31-&#x52A8;&#x624B;&#x5B9E;&#x8DF5;"><a name="31-&#x52A8;&#x624B;&#x5B9E;&#x8DF5;" class="anchor-navigation-ex-anchor" href="#31-&#x52A8;&#x624B;&#x5B9E;&#x8DF5;"><i class="fa fa-link" aria-hidden="true"></i></a>3.1 &#x52A8;&#x624B;&#x5B9E;&#x8DF5;</h4>
<p>download code generate</p>
<pre class="language-"><code class="lang-bash"><span class="token builtin class-name">cd</span> <span class="token variable">$GOPATH</span>/src
<span class="token function">mkdir</span> -p k8s.io <span class="token operator">&amp;&amp;</span> <span class="token builtin class-name">cd</span> k8s.io
<span class="token function">git</span> clone https://github.com/kubernetes/code-generator.git
</code></pre>
<p>download one template</p>
<pre class="language-"><code class="lang-bash"><span class="token builtin class-name">cd</span> <span class="token variable">$GOPATH</span>/src/k8s.io
<span class="token function">git</span> clone https://github.com/xishengcai/example-controller.git
</code></pre>
<p>file struct</p>
<pre class="language-"><code class="lang-bash"><span class="token punctuation">[</span>root@cn-hongkong example-controller<span class="token punctuation">]</span><span class="token comment"># tree</span>
<span class="token builtin class-name">.</span>
&#x251C;&#x2500;&#x2500; hack
&#x2502;   &#x251C;&#x2500;&#x2500; boilerplate.go.txt
&#x2502;   &#x251C;&#x2500;&#x2500; update-codegen.sh
&#x2502;   &#x2514;&#x2500;&#x2500; verify-codegen.sh
&#x2514;&#x2500;&#x2500; pkg
    &#x2514;&#x2500;&#x2500; apis
        &#x2514;&#x2500;&#x2500; examplecontroller
            &#x251C;&#x2500;&#x2500; register.go
            &#x2514;&#x2500;&#x2500; v1
                &#x251C;&#x2500;&#x2500; doc.go
                &#x251C;&#x2500;&#x2500; register.go
                &#x2514;&#x2500;&#x2500; types.go
</code></pre>
<p>&#x4FEE;&#x6539;&#x6A21;&#x677F;&#x4E2D;&#x7684; group, version, object type&#xFF0C; &#x7136;&#x540E;&#x4F7F;&#x7528;&#x811A;&#x672C;&#x81EA;&#x52A8;&#x751F;&#x6210;&#x4EE3;&#x7801;</p>
<pre class="language-"><code class="lang-bash">./hack/update-codegen.sh
</code></pre>
<p>&#x81EA;&#x52A8;&#x751F;&#x6210;&#x4E86; clientset&#xFF0C;informers&#xFF0C;listers &#x4E09;&#x4E2A;&#x6587;&#x4EF6;&#x5939;&#x4E0B;&#x7684;&#x6587;&#x4EF6;&#x548C;apis&#x4E0B;&#x7684;zz_generated.deepcopy.go&#x6587;&#x4EF6;&#x3002;</p>
<p>&#x5176;&#x4E2D;zz_generated.deepcopy.go&#x4E2D;&#x5305;&#x542B; pkg/apis/samplecontroller/v1alpha1/types.go &#x4E2D;&#x5B9A;&#x4E49;&#x7684;&#x7ED3;&#x6784;&#x4F53;&#x7684; DeepCopy() &#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x53E6;&#x5916;&#x4E09;&#x4E2A;&#x6587;&#x4EF6;&#x5939;clientset&#xFF0C;informers&#xFF0C;listers&#x4E0B;&#x90FD;&#x662F; Kubernetes &#x751F;&#x6210;&#x7684;&#x5BA2;&#x6237;&#x7AEF;&#x5E93;&#xFF0C;&#x5728; controller &#x4E2D;&#x4F1A;&#x7528;&#x5230;&#x3002;</p>
<pre class="language-"><code>[root@cn-hongkong example-controller]# ./hack/update-codegen.sh
Generating deepcopy funcs
Generating clientset for examplecontroller:v1 at k8s.io/example-controller/pkg/generated/clientset
Generating listers for examplecontroller:v1 at k8s.io/example-controller/pkg/generated/listers
Generating informers for examplecontroller:v1 at k8s.io/example-controller/pkg/generated/informers
</code></pre><p>file struct</p>
<pre class="language-"><code>[root@cn-hongkong example-controller]# tree
.
&#x251C;&#x2500;&#x2500; hack
&#x2502;   &#x251C;&#x2500;&#x2500; boilerplate.go.txt
&#x2502;   &#x251C;&#x2500;&#x2500; update-codegen.sh
&#x2502;   &#x2514;&#x2500;&#x2500; verify-codegen.sh
&#x2514;&#x2500;&#x2500; pkg
    &#x251C;&#x2500;&#x2500; apis
    &#x2502;   &#x2514;&#x2500;&#x2500; examplecontroller
    &#x2502;       &#x251C;&#x2500;&#x2500; register.go
    &#x2502;       &#x2514;&#x2500;&#x2500; v1
    &#x2502;           &#x251C;&#x2500;&#x2500; doc.go
    &#x2502;           &#x251C;&#x2500;&#x2500; register.go
    &#x2502;           &#x251C;&#x2500;&#x2500; types.go
    &#x2502;           &#x2514;&#x2500;&#x2500; zz_generated.deepcopy.go
    &#x2514;&#x2500;&#x2500; generated
        &#x251C;&#x2500;&#x2500; clientset
        &#x2502;   &#x2514;&#x2500;&#x2500; versioned
        &#x2502;       &#x251C;&#x2500;&#x2500; clientset.go
        &#x2502;       &#x251C;&#x2500;&#x2500; doc.go
        &#x2502;       &#x251C;&#x2500;&#x2500; fake
        &#x2502;       &#x2502;   &#x251C;&#x2500;&#x2500; clientset_generated.go
        &#x2502;       &#x2502;   &#x251C;&#x2500;&#x2500; doc.go
        &#x2502;       &#x2502;   &#x2514;&#x2500;&#x2500; register.go
        &#x2502;       &#x251C;&#x2500;&#x2500; scheme
        &#x2502;       &#x2502;   &#x251C;&#x2500;&#x2500; doc.go
        &#x2502;       &#x2502;   &#x2514;&#x2500;&#x2500; register.go
        &#x2502;       &#x2514;&#x2500;&#x2500; typed
        &#x2502;           &#x2514;&#x2500;&#x2500; examplecontroller
        &#x2502;               &#x2514;&#x2500;&#x2500; v1
        &#x2502;                   &#x251C;&#x2500;&#x2500; clustertesttype.go
        &#x2502;                   &#x251C;&#x2500;&#x2500; doc.go
        &#x2502;                   &#x251C;&#x2500;&#x2500; examplecontroller_client.go
        &#x2502;                   &#x251C;&#x2500;&#x2500; fake
        &#x2502;                   &#x2502;   &#x251C;&#x2500;&#x2500; doc.go
        &#x2502;                   &#x2502;   &#x251C;&#x2500;&#x2500; fake_clustertesttype.go
        &#x2502;                   &#x2502;   &#x251C;&#x2500;&#x2500; fake_examplecontroller_client.go
        &#x2502;                   &#x2502;   &#x2514;&#x2500;&#x2500; fake_testtype.go
        &#x2502;                   &#x251C;&#x2500;&#x2500; generated_expansion.go
        &#x2502;                   &#x2514;&#x2500;&#x2500; testtype.go
        &#x251C;&#x2500;&#x2500; informers
        &#x2502;   &#x2514;&#x2500;&#x2500; externalversions
        &#x2502;       &#x251C;&#x2500;&#x2500; examplecontroller
        &#x2502;       &#x2502;   &#x251C;&#x2500;&#x2500; interface.go
        &#x2502;       &#x2502;   &#x2514;&#x2500;&#x2500; v1
        &#x2502;       &#x2502;       &#x251C;&#x2500;&#x2500; clustertesttype.go
        &#x2502;       &#x2502;       &#x251C;&#x2500;&#x2500; interface.go
        &#x2502;       &#x2502;       &#x2514;&#x2500;&#x2500; testtype.go
        &#x2502;       &#x251C;&#x2500;&#x2500; factory.go
        &#x2502;       &#x251C;&#x2500;&#x2500; generic.go
        &#x2502;       &#x2514;&#x2500;&#x2500; internalinterfaces
        &#x2502;           &#x2514;&#x2500;&#x2500; factory_interfaces.go
        &#x2514;&#x2500;&#x2500; listers
            &#x2514;&#x2500;&#x2500; examplecontroller
                &#x2514;&#x2500;&#x2500; v1
                    &#x251C;&#x2500;&#x2500; clustertesttype.go
                    &#x251C;&#x2500;&#x2500; expansion_generated.go
                    &#x2514;&#x2500;&#x2500; testtype.go
</code></pre><p>&#x5177;&#x4F53;&#x7684;controller &#x7F16;&#x5199;&#x53EF;&#x4EE5;&#x53C2;&#x8003; <a href="https://github.com/kubernetes/sample-controller/blob/master/controller.go" target="_blank">https://github.com/kubernetes/sample-controller/blob/master/controller.go</a> </p>
<pre class="language-"><code class="lang-go"><span class="token comment">//main.go</span>
    <span class="token comment">// &#x521B;&#x5EFA;k8s&#x539F;&#x751F;&#x8D44;&#x6E90;&#x7684;client</span>
    kubeClient<span class="token punctuation">,</span> err <span class="token operator">:=</span> kubernetes<span class="token punctuation">.</span><span class="token function">NewForConfig</span><span class="token punctuation">(</span>cfg<span class="token punctuation">)</span>
    <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
        klog<span class="token punctuation">.</span><span class="token function">Fatalf</span><span class="token punctuation">(</span><span class="token string">&quot;Error building kubernetes clientset: %s&quot;</span><span class="token punctuation">,</span> err<span class="token punctuation">.</span><span class="token function">Error</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

    <span class="token comment">// &#x521B;&#x5EFA;&#x81EA;&#x5B9A;&#x4E49;&#x8D44;&#x6E90;&#x7684;client</span>
    exampleClient<span class="token punctuation">,</span> err <span class="token operator">:=</span> clientset<span class="token punctuation">.</span><span class="token function">NewForConfig</span><span class="token punctuation">(</span>cfg<span class="token punctuation">)</span>
    <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
        klog<span class="token punctuation">.</span><span class="token function">Fatalf</span><span class="token punctuation">(</span><span class="token string">&quot;Error building example clientset: %s&quot;</span><span class="token punctuation">,</span> err<span class="token punctuation">.</span><span class="token function">Error</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

    <span class="token comment">// &#x751F;&#x6210;informerFactrory</span>
    kubeInformerFactory <span class="token operator">:=</span> kubeinformers<span class="token punctuation">.</span><span class="token function">NewSharedInformerFactory</span><span class="token punctuation">(</span>kubeClient<span class="token punctuation">,</span> time<span class="token punctuation">.</span>Second<span class="token operator">*</span><span class="token number">30</span><span class="token punctuation">)</span>
    exampleInformerFactory <span class="token operator">:=</span> informers<span class="token punctuation">.</span><span class="token function">NewSharedInformerFactory</span><span class="token punctuation">(</span>exampleClient<span class="token punctuation">,</span> time<span class="token punctuation">.</span>Second<span class="token operator">*</span><span class="token number">30</span><span class="token punctuation">)</span>

    controller <span class="token operator">:=</span> <span class="token function">NewController</span><span class="token punctuation">(</span>kubeClient<span class="token punctuation">,</span> exampleClient<span class="token punctuation">,</span>
        kubeInformerFactory<span class="token punctuation">.</span><span class="token function">Apps</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">V1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Deployments</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        exampleInformerFactory<span class="token punctuation">.</span><span class="token function">Samplecontroller</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">V1alpha1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Foos</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

    <span class="token comment">// &#x8FD0;&#x884C; Informer&#xFF0C;Start &#x65B9;&#x6CD5;&#x4E3A;&#x975E;&#x963B;&#x585E;&#xFF0C;&#x4F1A;&#x8FD0;&#x884C;&#x5728;&#x5355;&#x72EC;&#x7684; goroutine &#x4E2D;</span>
    kubeInformerFactory<span class="token punctuation">.</span><span class="token function">Start</span><span class="token punctuation">(</span>stopCh<span class="token punctuation">)</span>
    exampleInformerFactory<span class="token punctuation">.</span><span class="token function">Start</span><span class="token punctuation">(</span>stopCh<span class="token punctuation">)</span>

    <span class="token comment">// &#x591A;&#x7EBF;&#x7A0B;&#x8FD0;&#x884C;controller</span>
    <span class="token keyword">if</span> err <span class="token operator">=</span> controller<span class="token punctuation">.</span><span class="token function">Run</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> stopCh<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
        klog<span class="token punctuation">.</span><span class="token function">Fatalf</span><span class="token punctuation">(</span><span class="token string">&quot;Error running controller: %s&quot;</span><span class="token punctuation">,</span> err<span class="token punctuation">.</span><span class="token function">Error</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

<span class="token comment">//controller.go</span>
<span class="token comment">// Controller is the controller implementation for Foo resources</span>
<span class="token comment">// NewController returns a new sample controller</span>
<span class="token keyword">func</span> <span class="token function">NewController</span><span class="token punctuation">(</span>
    <span class="token comment">// &#x5C06; CRD &#x8D44;&#x6E90;&#x7C7B;&#x578B;&#x5B9A;&#x4E49;&#x52A0;&#x5165;&#x5230; Kubernetes &#x7684; Scheme &#x4E2D;&#xFF0C;&#x4EE5;&#x4FBF; Events &#x53EF;&#x4EE5;&#x8BB0;&#x5F55; CRD &#x7684;&#x4E8B;&#x4EF6;</span>
    utilruntime<span class="token punctuation">.</span><span class="token function">Must</span><span class="token punctuation">(</span>samplescheme<span class="token punctuation">.</span><span class="token function">AddToScheme</span><span class="token punctuation">(</span>scheme<span class="token punctuation">.</span>Scheme<span class="token punctuation">)</span><span class="token punctuation">)</span>
    eventBroadcaster<span class="token punctuation">.</span><span class="token function">StartRecordingToSink</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>typedcorev1<span class="token punctuation">.</span>EventSinkImpl<span class="token punctuation">{</span>Interface<span class="token punctuation">:</span> kubeclientset<span class="token punctuation">.</span><span class="token function">CoreV1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Events</span><span class="token punctuation">(</span><span class="token string">&quot;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
     <span class="token comment">// &#x76D1;&#x542C; CRD &#x7C7B;&#x578B;&apos;Foo&apos;&#x5E76;&#x6CE8;&#x518C; ResourceEventHandler &#x65B9;&#x6CD5;&#xFF0C;&#x5F53;&apos;Foo&apos;&#x7684;&#x5B9E;&#x4F8B;&#x53D8;&#x5316;&#x65F6;&#x8FDB;&#x884C;&#x5904;&#x7406;</span>
    fooInformer<span class="token punctuation">.</span><span class="token function">Informer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">AddEventHandler</span><span class="token punctuation">(</span>cache<span class="token punctuation">.</span>ResourceEventHandlerFuncs<span class="token punctuation">{</span>
        AddFunc<span class="token punctuation">:</span> controller<span class="token punctuation">.</span>enqueueFoo<span class="token punctuation">,</span>
        UpdateFunc<span class="token punctuation">:</span> <span class="token keyword">func</span><span class="token punctuation">(</span>old<span class="token punctuation">,</span> <span class="token builtin">new</span> <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            controller<span class="token punctuation">.</span><span class="token function">enqueueFoo</span><span class="token punctuation">(</span><span class="token builtin">new</span><span class="token punctuation">)</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>

    <span class="token comment">// &#x76D1;&#x542C; Deployment &#x53D8;&#x5316;&#x5E76;&#x6CE8;&#x518C; ResourceEventHandler &#x65B9;&#x6CD5;&#xFF0C;</span>
    <span class="token comment">// &#x5F53;&#x5B83;&#x7684; ownerReferences &#x4E3A; Foo &#x7C7B;&#x578B;&#x5B9E;&#x4F8B;&#x65F6;&#xFF0C;&#x5C06;&#x8BE5; Foo &#x8D44;&#x6E90;&#x52A0;&#x5165; work queue</span>
    deploymentInformer<span class="token punctuation">.</span><span class="token function">Informer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">AddEventHandler</span><span class="token punctuation">(</span>cache<span class="token punctuation">.</span>ResourceEventHandlerFuncs<span class="token punctuation">{</span>
        AddFunc<span class="token punctuation">:</span> controller<span class="token punctuation">.</span>handleObject<span class="token punctuation">,</span>
        UpdateFunc<span class="token punctuation">:</span> <span class="token keyword">func</span><span class="token punctuation">(</span>old<span class="token punctuation">,</span> <span class="token builtin">new</span> <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            newDepl <span class="token operator">:=</span> <span class="token builtin">new</span><span class="token punctuation">.</span><span class="token punctuation">(</span><span class="token operator">*</span>appsv1<span class="token punctuation">.</span>Deployment<span class="token punctuation">)</span>
            oldDepl <span class="token operator">:=</span> old<span class="token punctuation">.</span><span class="token punctuation">(</span><span class="token operator">*</span>appsv1<span class="token punctuation">.</span>Deployment<span class="token punctuation">)</span>
            <span class="token keyword">if</span> newDepl<span class="token punctuation">.</span>ResourceVersion <span class="token operator">==</span> oldDepl<span class="token punctuation">.</span>ResourceVersion <span class="token punctuation">{</span>
                <span class="token keyword">return</span>
            <span class="token punctuation">}</span>
            controller<span class="token punctuation">.</span><span class="token function">handleObject</span><span class="token punctuation">(</span><span class="token builtin">new</span><span class="token punctuation">)</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        DeleteFunc<span class="token punctuation">:</span> controller<span class="token punctuation">.</span>handleObject<span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>

    <span class="token keyword">return</span> controller
<span class="token punctuation">}</span>


<span class="token keyword">func</span> <span class="token punctuation">(</span>c <span class="token operator">*</span>Controller<span class="token punctuation">)</span> <span class="token function">Run</span><span class="token punctuation">(</span>threadiness <span class="token builtin">int</span><span class="token punctuation">,</span> stopCh <span class="token operator">&lt;-</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
    <span class="token keyword">defer</span> utilruntime<span class="token punctuation">.</span><span class="token function">HandleCrash</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">defer</span> c<span class="token punctuation">.</span>workqueue<span class="token punctuation">.</span><span class="token function">ShutDown</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

    <span class="token comment">// &#x5728;&#x542F;&#x52A8; worker &#x524D;&#x7B49;&#x5F85;&#x7F13;&#x5B58;&#x540C;&#x6B65;</span>
    <span class="token keyword">if</span> ok <span class="token operator">:=</span> cache<span class="token punctuation">.</span><span class="token function">WaitForCacheSync</span><span class="token punctuation">(</span>stopCh<span class="token punctuation">,</span> c<span class="token punctuation">.</span>deploymentsSynced<span class="token punctuation">,</span> c<span class="token punctuation">.</span>foosSynced<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">!</span>ok <span class="token punctuation">{</span>
        <span class="token keyword">return</span> fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;failed to wait for caches to sync&quot;</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

    <span class="token comment">// &#x8FD0;&#x884C;&#x4E24;&#x4E2A; worker &#x6765;&#x5904;&#x7406;&#x8D44;&#x6E90;</span>
    <span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> threadiness<span class="token punctuation">;</span> i<span class="token operator">++</span> <span class="token punctuation">{</span>
        <span class="token keyword">go</span> wait<span class="token punctuation">.</span><span class="token function">Until</span><span class="token punctuation">(</span>c<span class="token punctuation">.</span>runWorker<span class="token punctuation">,</span> time<span class="token punctuation">.</span>Second<span class="token punctuation">,</span> stopCh<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
    <span class="token operator">&lt;-</span>stopCh
    <span class="token keyword">return</span> <span class="token boolean">nil</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token punctuation">(</span>c <span class="token operator">*</span>Controller<span class="token punctuation">)</span> <span class="token function">runWorker</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// &#x65E0;&#x9650;&#x5FAA;&#x73AF;&#xFF0C;&#x4E0D;&#x65AD;&#x7684;&#x8C03;&#x7528; processNextWorkItem &#x5904;&#x7406;&#x4E0B;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;</span>
    <span class="token keyword">for</span> c<span class="token punctuation">.</span><span class="token function">processNextWorkItem</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token punctuation">(</span>c <span class="token operator">*</span>Controller<span class="token punctuation">)</span> <span class="token function">processNextWorkItem</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">bool</span> <span class="token punctuation">{</span>
    obj<span class="token punctuation">,</span> shutdown <span class="token operator">:=</span> c<span class="token punctuation">.</span>workqueue<span class="token punctuation">.</span><span class="token function">Get</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

    <span class="token keyword">if</span> shutdown <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token boolean">false</span>
    <span class="token punctuation">}</span>

    err <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
        <span class="token comment">// &#x8C03;&#x7528; workqueue.Done(obj) &#x65B9;&#x6CD5;&#x544A;&#x8BC9; workqueue &#x5F53;&#x524D;&#x9879;&#x5DF2;&#x7ECF;&#x5904;&#x7406;&#x5B8C;&#x6BD5;&#xFF0C;</span>
        <span class="token keyword">defer</span> c<span class="token punctuation">.</span>workqueue<span class="token punctuation">.</span><span class="token function">Done</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span>
        <span class="token keyword">var</span> key <span class="token builtin">string</span>
        <span class="token keyword">var</span> ok <span class="token builtin">bool</span>
        <span class="token keyword">if</span> key<span class="token punctuation">,</span> ok <span class="token operator">=</span> obj<span class="token punctuation">.</span><span class="token punctuation">(</span><span class="token builtin">string</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">!</span>ok <span class="token punctuation">{</span>
            <span class="token comment">// &#x65E0;&#x6548;&#x7684;&#x9879;&#x8C03;&#x7528;Forget&#x65B9;&#x6CD5;&#xFF0C;&#x907F;&#x514D;&#x91CD;&#x65B0;&#x5165;&#x961F;&#x3002;</span>
            c<span class="token punctuation">.</span>workqueue<span class="token punctuation">.</span><span class="token function">Forget</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span>
            utilruntime<span class="token punctuation">.</span><span class="token function">HandleError</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;expected string in workqueue but got %#v&quot;</span><span class="token punctuation">,</span> obj<span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token keyword">return</span> <span class="token boolean">nil</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">if</span> err <span class="token operator">:=</span> c<span class="token punctuation">.</span><span class="token function">syncHandler</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
            <span class="token comment">// &#x653E;&#x56DE;workqueue&#x907F;&#x514D;&#x5076;&#x53D1;&#x7684;&#x5F02;&#x5E38;</span>
            c<span class="token punctuation">.</span>workqueue<span class="token punctuation">.</span><span class="token function">AddRateLimited</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span>
            <span class="token keyword">return</span> fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;error syncing &apos;%s&apos;: %s, requeuing&quot;</span><span class="token punctuation">,</span> key<span class="token punctuation">,</span> err<span class="token punctuation">.</span><span class="token function">Error</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token punctuation">}</span>
        c<span class="token punctuation">.</span>workqueue<span class="token punctuation">.</span><span class="token function">Forget</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span>
        klog<span class="token punctuation">.</span><span class="token function">Infof</span><span class="token punctuation">(</span><span class="token string">&quot;Successfully synced &apos;%s&apos;&quot;</span><span class="token punctuation">,</span> key<span class="token punctuation">)</span>
        <span class="token keyword">return</span> <span class="token boolean">nil</span>
    <span class="token punctuation">}</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span>

    <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
        utilruntime<span class="token punctuation">.</span><span class="token function">HandleError</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span>
        <span class="token keyword">return</span> <span class="token boolean">true</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">return</span> <span class="token boolean">true</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x5B9E;&#x73B0;fool&#x7684;&#x526F;&#x672C;&#x6570;&#x548C;&#x671F;&#x671B;&#x503C;&#x4E00;&#x81F4;</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>c <span class="token operator">*</span>Controller<span class="token punctuation">)</span> <span class="token function">syncHandler</span><span class="token punctuation">(</span>key <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
    namespace<span class="token punctuation">,</span> name<span class="token punctuation">,</span> err <span class="token operator">:=</span> cache<span class="token punctuation">.</span><span class="token function">SplitMetaNamespaceKey</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span>
    <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
        utilruntime<span class="token punctuation">.</span><span class="token function">HandleError</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;invalid resource key: %s&quot;</span><span class="token punctuation">,</span> key<span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token keyword">return</span> <span class="token boolean">nil</span>
    <span class="token punctuation">}</span>

    foo<span class="token punctuation">,</span> err <span class="token operator">:=</span> c<span class="token punctuation">.</span>foosLister<span class="token punctuation">.</span><span class="token function">Foos</span><span class="token punctuation">(</span>namespace<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Get</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span>
    <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> errors<span class="token punctuation">.</span><span class="token function">IsNotFound</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            utilruntime<span class="token punctuation">.</span><span class="token function">HandleError</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;foo &apos;%s&apos; in work queue no longer exists&quot;</span><span class="token punctuation">,</span> key<span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token keyword">return</span> <span class="token boolean">nil</span>
        <span class="token punctuation">}</span>

        <span class="token keyword">return</span> err
    <span class="token punctuation">}</span>

    deploymentName <span class="token operator">:=</span> foo<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>DeploymentName
    <span class="token keyword">if</span> deploymentName <span class="token operator">==</span> <span class="token string">&quot;&quot;</span> <span class="token punctuation">{</span>
        utilruntime<span class="token punctuation">.</span><span class="token function">HandleError</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;%s: deployment name must be specified&quot;</span><span class="token punctuation">,</span> key<span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token keyword">return</span> <span class="token boolean">nil</span>
    <span class="token punctuation">}</span>

    deployment<span class="token punctuation">,</span> err <span class="token operator">:=</span> c<span class="token punctuation">.</span>deploymentsLister<span class="token punctuation">.</span><span class="token function">Deployments</span><span class="token punctuation">(</span>foo<span class="token punctuation">.</span>Namespace<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Get</span><span class="token punctuation">(</span>deploymentName<span class="token punctuation">)</span>
    <span class="token keyword">if</span> errors<span class="token punctuation">.</span><span class="token function">IsNotFound</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        deployment<span class="token punctuation">,</span> err <span class="token operator">=</span> c<span class="token punctuation">.</span>kubeclientset<span class="token punctuation">.</span><span class="token function">AppsV1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Deployments</span><span class="token punctuation">(</span>foo<span class="token punctuation">.</span>Namespace<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Create</span><span class="token punctuation">(</span><span class="token function">newDeployment</span><span class="token punctuation">(</span>foo<span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
    <span class="token comment">//...</span>

    <span class="token keyword">if</span> <span class="token operator">!</span>metav1<span class="token punctuation">.</span><span class="token function">IsControlledBy</span><span class="token punctuation">(</span>deployment<span class="token punctuation">,</span> foo<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        msg <span class="token operator">:=</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span>MessageResourceExists<span class="token punctuation">,</span> deployment<span class="token punctuation">.</span>Name<span class="token punctuation">)</span>
        c<span class="token punctuation">.</span>recorder<span class="token punctuation">.</span><span class="token function">Event</span><span class="token punctuation">(</span>foo<span class="token punctuation">,</span> corev1<span class="token punctuation">.</span>EventTypeWarning<span class="token punctuation">,</span> ErrResourceExists<span class="token punctuation">,</span> msg<span class="token punctuation">)</span>
        <span class="token keyword">return</span> fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span>msg<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">if</span> foo<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token operator">&amp;&amp;</span> <span class="token operator">*</span>foo<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas <span class="token operator">!=</span> <span class="token operator">*</span>deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas <span class="token punctuation">{</span>
        klog<span class="token punctuation">.</span><span class="token function">V</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Infof</span><span class="token punctuation">(</span><span class="token string">&quot;Foo %s replicas: %d, deployment replicas: %d&quot;</span><span class="token punctuation">,</span> name<span class="token punctuation">,</span> <span class="token operator">*</span>foo<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">,</span> <span class="token operator">*</span>deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span>
        deployment<span class="token punctuation">,</span> err <span class="token operator">=</span> c<span class="token punctuation">.</span>kubeclientset<span class="token punctuation">.</span><span class="token function">AppsV1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Deployments</span><span class="token punctuation">(</span>foo<span class="token punctuation">.</span>Namespace<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Update</span><span class="token punctuation">(</span><span class="token function">newDeployment</span><span class="token punctuation">(</span>foo<span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

    err <span class="token operator">=</span> c<span class="token punctuation">.</span><span class="token function">updateFooStatus</span><span class="token punctuation">(</span>foo<span class="token punctuation">,</span> deployment<span class="token punctuation">)</span>
    <span class="token comment">//....</span>
    c<span class="token punctuation">.</span>recorder<span class="token punctuation">.</span><span class="token function">Event</span><span class="token punctuation">(</span>foo<span class="token punctuation">,</span> corev1<span class="token punctuation">.</span>EventTypeNormal<span class="token punctuation">,</span> SuccessSynced<span class="token punctuation">,</span> MessageResourceSynced<span class="token punctuation">)</span>
    <span class="token keyword">return</span> <span class="token boolean">nil</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token punctuation">(</span>c <span class="token operator">*</span>Controller<span class="token punctuation">)</span> <span class="token function">updateFooStatus</span><span class="token punctuation">(</span>foo <span class="token operator">*</span>samplev1alpha1<span class="token punctuation">.</span>Foo<span class="token punctuation">,</span> deployment <span class="token operator">*</span>appsv1<span class="token punctuation">.</span>Deployment<span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
    fooCopy <span class="token operator">:=</span> foo<span class="token punctuation">.</span><span class="token function">DeepCopy</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    fooCopy<span class="token punctuation">.</span>Status<span class="token punctuation">.</span>AvailableReplicas <span class="token operator">=</span> deployment<span class="token punctuation">.</span>Status<span class="token punctuation">.</span>AvailableReplicas
    <span class="token boolean">_</span><span class="token punctuation">,</span> err <span class="token operator">:=</span> c<span class="token punctuation">.</span>sampleclientset<span class="token punctuation">.</span><span class="token function">SamplecontrollerV1alpha1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Foos</span><span class="token punctuation">(</span>foo<span class="token punctuation">.</span>Namespace<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Update</span><span class="token punctuation">(</span>fooCopy<span class="token punctuation">)</span>
    <span class="token keyword">return</span> err
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token punctuation">(</span>c <span class="token operator">*</span>Controller<span class="token punctuation">)</span> <span class="token function">enqueueFoo</span><span class="token punctuation">(</span>obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">var</span> key <span class="token builtin">string</span>
    <span class="token keyword">var</span> err <span class="token builtin">error</span>
    <span class="token keyword">if</span> key<span class="token punctuation">,</span> err <span class="token operator">=</span> cache<span class="token punctuation">.</span><span class="token function">MetaNamespaceKeyFunc</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
        utilruntime<span class="token punctuation">.</span><span class="token function">HandleError</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span>
        <span class="token keyword">return</span>
    <span class="token punctuation">}</span>
    c<span class="token punctuation">.</span>workqueue<span class="token punctuation">.</span><span class="token function">Add</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token punctuation">(</span>c <span class="token operator">*</span>Controller<span class="token punctuation">)</span> <span class="token function">handleObject</span><span class="token punctuation">(</span>obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">var</span> object metav1<span class="token punctuation">.</span>Object
    <span class="token keyword">var</span> ok <span class="token builtin">bool</span>
    <span class="token keyword">if</span> object<span class="token punctuation">,</span> ok <span class="token operator">=</span> obj<span class="token punctuation">.</span><span class="token punctuation">(</span>metav1<span class="token punctuation">.</span>Object<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">!</span>ok <span class="token punctuation">{</span>
        tombstone<span class="token punctuation">,</span> ok <span class="token operator">:=</span> obj<span class="token punctuation">.</span><span class="token punctuation">(</span>cache<span class="token punctuation">.</span>DeletedFinalStateUnknown<span class="token punctuation">)</span>
        <span class="token keyword">if</span> <span class="token operator">!</span>ok <span class="token punctuation">{</span>
            utilruntime<span class="token punctuation">.</span><span class="token function">HandleError</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;error decoding object, invalid type&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token keyword">return</span>
        <span class="token punctuation">}</span>
        object<span class="token punctuation">,</span> ok <span class="token operator">=</span> tombstone<span class="token punctuation">.</span>Obj<span class="token punctuation">.</span><span class="token punctuation">(</span>metav1<span class="token punctuation">.</span>Object<span class="token punctuation">)</span>
        <span class="token keyword">if</span> <span class="token operator">!</span>ok <span class="token punctuation">{</span>
            utilruntime<span class="token punctuation">.</span><span class="token function">HandleError</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;error decoding object tombstone, invalid type&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token keyword">return</span>
        <span class="token punctuation">}</span>
        klog<span class="token punctuation">.</span><span class="token function">V</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Infof</span><span class="token punctuation">(</span><span class="token string">&quot;Recovered deleted object &apos;%s&apos; from tombstone&quot;</span><span class="token punctuation">,</span> object<span class="token punctuation">.</span><span class="token function">GetName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
    klog<span class="token punctuation">.</span><span class="token function">V</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Infof</span><span class="token punctuation">(</span><span class="token string">&quot;Processing object: %s&quot;</span><span class="token punctuation">,</span> object<span class="token punctuation">.</span><span class="token function">GetName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token keyword">if</span> ownerRef <span class="token operator">:=</span> metav1<span class="token punctuation">.</span><span class="token function">GetControllerOf</span><span class="token punctuation">(</span>object<span class="token punctuation">)</span><span class="token punctuation">;</span> ownerRef <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
        <span class="token comment">// If this object is not owned by a Foo, we should not do anything more</span>
        <span class="token comment">// with it.</span>
        <span class="token keyword">if</span> ownerRef<span class="token punctuation">.</span>Kind <span class="token operator">!=</span> <span class="token string">&quot;Foo&quot;</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span>
        <span class="token punctuation">}</span>

        foo<span class="token punctuation">,</span> err <span class="token operator">:=</span> c<span class="token punctuation">.</span>foosLister<span class="token punctuation">.</span><span class="token function">Foos</span><span class="token punctuation">(</span>object<span class="token punctuation">.</span><span class="token function">GetNamespace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Get</span><span class="token punctuation">(</span>ownerRef<span class="token punctuation">.</span>Name<span class="token punctuation">)</span>
        <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
            klog<span class="token punctuation">.</span><span class="token function">V</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Infof</span><span class="token punctuation">(</span><span class="token string">&quot;ignoring orphaned object &apos;%s&apos; of foo &apos;%s&apos;&quot;</span><span class="token punctuation">,</span> object<span class="token punctuation">.</span><span class="token function">GetSelfLink</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> ownerRef<span class="token punctuation">.</span>Name<span class="token punctuation">)</span>
            <span class="token keyword">return</span>
        <span class="token punctuation">}</span>

        c<span class="token punctuation">.</span><span class="token function">enqueueFoo</span><span class="token punctuation">(</span>foo<span class="token punctuation">)</span>
        <span class="token keyword">return</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">// .....</span>
</code></pre>
<p>--- &#x4EE5;&#x4E0B;&#x662F;&#x6E90;&#x7801;&#x5206;&#x6790;<a href="https://xigang.github.io/2019/09/21/client-go/" target="_blank">&#x539F;&#x6587; Kubernetes Client-Go Informer &#x5B9E;&#x73B0;&#x6E90;&#x7801;&#x5256;&#x6790;</a>-----</p>
<h3 id="4-informer"><a name="4-informer" class="anchor-navigation-ex-anchor" href="#4-informer"><i class="fa fa-link" aria-hidden="true"></i></a>4. informer</h3>
<p><img src="http://xisheng.vip/images/all-informer.png" alt="all-informer"></p>
<h4 id="41-use-sharedinformerfactory-create-eventinformer"><a name="41-use-sharedinformerfactory-create-eventinformer" class="anchor-navigation-ex-anchor" href="#41-use-sharedinformerfactory-create-eventinformer"><i class="fa fa-link" aria-hidden="true"></i></a>4.1 Use SharedInformerFactory Create EventInformer</h4>
<p>SharedInformerFactory&#x4E3A;kubernetes&#x4E2D;&#x7684;&#x6240;&#x6709;&#x8D44;&#x6E90;(API group versions)&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;shared informer&#x3002;&#x6240;&#x4EE5;controller&#x4E2D;&#x4F7F;&#x7528;&#x7684;&#x6240;&#x6709;Informer&#x90FD;&#x662F;
&#x4ECE;SharedInformerFactory&#x4E2D;&#x901A;&#x8FC7;GroupVersionResource&#x5F97;&#x5230;.</p>
<p>kubernetes &#x4E00;&#x5171;15&#x4E2A;informer</p>
<p>SharedInformerFactory&#x7684;&#x58F0;&#x660E;&#x7ED3;&#x6784;:</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">type</span> SharedInformerFactory <span class="token keyword">interface</span> <span class="token punctuation">{</span>
    internalinterfaces<span class="token punctuation">.</span>SharedInformerFactory
    <span class="token function">ForResource</span><span class="token punctuation">(</span>resource schema<span class="token punctuation">.</span>GroupVersionResource<span class="token punctuation">)</span> <span class="token punctuation">(</span>GenericInformer<span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span>
    <span class="token function">WaitForCacheSync</span><span class="token punctuation">(</span>stopCh <span class="token operator">&lt;-</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span><span class="token builtin">bool</span>

    <span class="token function">Admissionregistration</span><span class="token punctuation">(</span><span class="token punctuation">)</span> admissionregistration<span class="token punctuation">.</span>Interface
    <span class="token function">Apps</span><span class="token punctuation">(</span><span class="token punctuation">)</span> apps<span class="token punctuation">.</span>Interface
    <span class="token function">Auditregistration</span><span class="token punctuation">(</span><span class="token punctuation">)</span> auditregistration<span class="token punctuation">.</span>Interface
    <span class="token function">Autoscaling</span><span class="token punctuation">(</span><span class="token punctuation">)</span> autoscaling<span class="token punctuation">.</span>Interface
    <span class="token function">Batch</span><span class="token punctuation">(</span><span class="token punctuation">)</span> batch<span class="token punctuation">.</span>Interface
    <span class="token function">Certificates</span><span class="token punctuation">(</span><span class="token punctuation">)</span> certificates<span class="token punctuation">.</span>Interface
    <span class="token function">Coordination</span><span class="token punctuation">(</span><span class="token punctuation">)</span> coordination<span class="token punctuation">.</span>Interface
    <span class="token function">Core</span><span class="token punctuation">(</span><span class="token punctuation">)</span> core<span class="token punctuation">.</span>Interface
    <span class="token function">Events</span><span class="token punctuation">(</span><span class="token punctuation">)</span> events<span class="token punctuation">.</span>Interface
    <span class="token function">Extensions</span><span class="token punctuation">(</span><span class="token punctuation">)</span> extensions<span class="token punctuation">.</span>Interface
    <span class="token function">Networking</span><span class="token punctuation">(</span><span class="token punctuation">)</span> networking<span class="token punctuation">.</span>Interface
    <span class="token function">Policy</span><span class="token punctuation">(</span><span class="token punctuation">)</span> policy<span class="token punctuation">.</span>Interface
    <span class="token function">Rbac</span><span class="token punctuation">(</span><span class="token punctuation">)</span> rbac<span class="token punctuation">.</span>Interface
    <span class="token function">Scheduling</span><span class="token punctuation">(</span><span class="token punctuation">)</span> scheduling<span class="token punctuation">.</span>Interface
    <span class="token function">Settings</span><span class="token punctuation">(</span><span class="token punctuation">)</span> settings<span class="token punctuation">.</span>Interface
    <span class="token function">Storage</span><span class="token punctuation">(</span><span class="token punctuation">)</span> storage<span class="token punctuation">.</span>Interface
<span class="token punctuation">}</span>
</code></pre>
<p>Events&#x7684;&#x58F0;&#x660E;&#x7ED3;&#x6784;:</p>
<pre class="language-"><code class="lang-go"><span class="token comment">// Interface provides access to all the informers in this group version.</span>
<span class="token keyword">type</span> Interface <span class="token keyword">interface</span> <span class="token punctuation">{</span>
    <span class="token comment">// Events returns a EventInformer.</span>
    <span class="token function">Events</span><span class="token punctuation">(</span><span class="token punctuation">)</span> EventInformer
<span class="token punctuation">}</span>
</code></pre>
<p>EventInformer&#x7684;&#x58F0;&#x660E;&#x7ED3;&#x6784;:</p>
<pre class="language-"><code class="lang-go"><span class="token comment">// EventInformer provides access to a shared informer and lister for</span>
<span class="token comment">// Events.</span>
<span class="token keyword">type</span> EventInformer <span class="token keyword">interface</span> <span class="token punctuation">{</span>
    <span class="token function">Informer</span><span class="token punctuation">(</span><span class="token punctuation">)</span> cache<span class="token punctuation">.</span>SharedIndexInformer
    <span class="token function">Lister</span><span class="token punctuation">(</span><span class="token punctuation">)</span> v1beta1<span class="token punctuation">.</span>EventLister
<span class="token punctuation">}</span>
</code></pre>
<p>&#x8FD9;&#x6837;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x60F3;&#x4F7F;&#x7528;EventInformer,&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x5C31;&#x76F4;&#x63A5;&#x5728;SharedInformerFactory&#x4E2D;&#x83B7;&#x53D6;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x7684;Informer&#x5373;&#x53EF;&#x3002;
&#x53EA;&#x9700;&#x8981;&#x6267;&#x884C;&#x4E0B;&#x9762;&#x7684;&#x4E24;&#x884C;&#x4EE3;&#x7801;:</p>
<pre class="language-"><code class="lang-go">sharedInformers <span class="token operator">:=</span> informers<span class="token punctuation">.</span><span class="token function">NewSharedInformerFactory</span><span class="token punctuation">(</span>clientset<span class="token punctuation">,</span> viper<span class="token punctuation">.</span><span class="token function">GetDuration</span><span class="token punctuation">(</span><span class="token string">&quot;resync-interval&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

eventsInformer <span class="token operator">:=</span> sharedInformers<span class="token punctuation">.</span><span class="token function">Core</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">V1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Events</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre>
<h4 id="42-register-informer"><a name="42-register-informer" class="anchor-navigation-ex-anchor" href="#42-register-informer"><i class="fa fa-link" aria-hidden="true"></i></a>4.2 Register Informer</h4>
<p>&#x5DF2;&#x7ECF;&#x83B7;&#x53D6;&#x4E86;&#x6211;&#x4EEC;&#x60F3;&#x8981;&#x4F7F;&#x7528;&#x7684;EventInformer&#xFF0C;&#x63A5;&#x4E0B;&#x6765;&#x5C31;&#x9700;&#x8981;&#x5C06;&#x8BE5;Informer&#x6CE8;&#x518C;&#x5230;factory(SharedInformerFactory),
&#x5176;&#x5B9E;&#x5728;&#x8C03;&#x7528;eventsInformer.Informer()&#x65F6;&#xFF0C;&#x5C31;&#x5DF2;&#x7ECF;&#x505A;&#x4E86;Informer&#x6CE8;&#x518C;&#x7684;&#x5DE5;&#x4F5C;,&#x4E4B;&#x540E;&#x901A;&#x8FC7;informerFactory.Start()
&#x5C06;&#x6240;&#x6709;&#x6CE8;&#x518C;&#x5230;factory&#x7684;Informer&#x90FD;&#x542F;&#x52A8;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x662F;&#x6CE8;&#x518C;EventInformer&#x7684;&#x4E00;&#x4E2A;&#x5B9E;&#x73B0;&#x903B;&#x8F91;:</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token function">NewFilteredEventInformer</span><span class="token punctuation">(</span>client kubernetes<span class="token punctuation">.</span>Interface<span class="token punctuation">,</span> namespace <span class="token builtin">string</span><span class="token punctuation">,</span> resyncPeriod time<span class="token punctuation">.</span>Duration<span class="token punctuation">,</span>
 indexers cache<span class="token punctuation">.</span>Indexers<span class="token punctuation">,</span> tweakListOptions internalinterfaces<span class="token punctuation">.</span>TweakListOptionsFunc<span class="token punctuation">)</span> cache<span class="token punctuation">.</span>SharedIndexInformer <span class="token punctuation">{</span>
    <span class="token keyword">return</span> cache<span class="token punctuation">.</span><span class="token function">NewSharedIndexInformer</span><span class="token punctuation">(</span>
        <span class="token operator">&amp;</span>cache<span class="token punctuation">.</span>ListWatch<span class="token punctuation">{</span>
            ListFunc<span class="token punctuation">:</span> <span class="token keyword">func</span><span class="token punctuation">(</span>options metav1<span class="token punctuation">.</span>ListOptions<span class="token punctuation">)</span> <span class="token punctuation">(</span>runtime<span class="token punctuation">.</span>Object<span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">if</span> tweakListOptions <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
                    <span class="token function">tweakListOptions</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>options<span class="token punctuation">)</span>
                <span class="token punctuation">}</span>
                <span class="token keyword">return</span> client<span class="token punctuation">.</span><span class="token function">CoreV1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Events</span><span class="token punctuation">(</span>namespace<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">List</span><span class="token punctuation">(</span>options<span class="token punctuation">)</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
            WatchFunc<span class="token punctuation">:</span> <span class="token keyword">func</span><span class="token punctuation">(</span>options metav1<span class="token punctuation">.</span>ListOptions<span class="token punctuation">)</span> <span class="token punctuation">(</span>watch<span class="token punctuation">.</span>Interface<span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">if</span> tweakListOptions <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
                    <span class="token function">tweakListOptions</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>options<span class="token punctuation">)</span>
                <span class="token punctuation">}</span>
                <span class="token keyword">return</span> client<span class="token punctuation">.</span><span class="token function">CoreV1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Events</span><span class="token punctuation">(</span>namespace<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Watch</span><span class="token punctuation">(</span>options<span class="token punctuation">)</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token operator">&amp;</span>corev1<span class="token punctuation">.</span>Event<span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
        resyncPeriod<span class="token punctuation">,</span>
        indexers<span class="token punctuation">,</span>
    <span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>eventInformer<span class="token punctuation">)</span> <span class="token function">defaultInformer</span><span class="token punctuation">(</span>client kubernetes<span class="token punctuation">.</span>Interface<span class="token punctuation">,</span> resyncPeriod time<span class="token punctuation">.</span>Duration<span class="token punctuation">)</span> cache<span class="token punctuation">.</span>SharedIndexInformer <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">NewFilteredEventInformer</span><span class="token punctuation">(</span>client<span class="token punctuation">,</span> f<span class="token punctuation">.</span>namespace<span class="token punctuation">,</span> resyncPeriod<span class="token punctuation">,</span> cache<span class="token punctuation">.</span>Indexers<span class="token punctuation">{</span>cache<span class="token punctuation">.</span>NamespaceIndex<span class="token punctuation">:</span> cache<span class="token punctuation">.</span>MetaNamespaceIndexFunc<span class="token punctuation">}</span><span class="token punctuation">,</span> f<span class="token punctuation">.</span>tweakListOptions<span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>eventInformer<span class="token punctuation">)</span> <span class="token function">Informer</span><span class="token punctuation">(</span><span class="token punctuation">)</span> cache<span class="token punctuation">.</span>SharedIndexInformer <span class="token punctuation">{</span>
    <span class="token keyword">return</span> f<span class="token punctuation">.</span>factory<span class="token punctuation">.</span><span class="token function">InformerFor</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>corev1<span class="token punctuation">.</span>Event<span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> f<span class="token punctuation">.</span>defaultInformer<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>sharedInformerFactory&#x7684;&#x58F0;&#x660E;&#x7ED3;&#x6784;, &#x5728;&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x4E3B;&#x8981;&#x5173;&#x6CE8;informers&#x548C;startedInformers&#xFF0C;&#x5176;&#x4E2D;informers&#x4E3B;&#x8981;&#x7684;&#x662F;&#x5B58;&#x50A8;&#xFF0C;
&#x5411;&#x8BE5;factory&#x5DF2;&#x7ECF;&#x6CE8;&#x518C;&#x7684;Informer,&#x800C;startedInformers&#x4E3B;&#x8981;&#x8BB0;&#x5F55;&#x54EA;&#x4E9B;Informer&#x5DF2;&#x7ECF;&#x542F;&#x52A8;&#x4E86;&#x3002;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">type</span> sharedInformerFactory <span class="token keyword">struct</span> <span class="token punctuation">{</span>
    client           kubernetes<span class="token punctuation">.</span>Interface
    namespace        <span class="token builtin">string</span>
    tweakListOptions internalinterfaces<span class="token punctuation">.</span>TweakListOptionsFunc
    lock             sync<span class="token punctuation">.</span>Mutex
    defaultResync    time<span class="token punctuation">.</span>Duration
    customResync     <span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span>time<span class="token punctuation">.</span>Duration

    informers <span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span>cache<span class="token punctuation">.</span>SharedIndexInformer
    <span class="token comment">// startedInformers is used for tracking which informers have been started.</span>
    <span class="token comment">// This allows Start() to be called multiple times safely.</span>
    startedInformers <span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span><span class="token builtin">bool</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4E0B;&#x9762;&#x8FD9;&#x6BB5;&#x4EE3;&#x7801;&#x7684;&#x903B;&#x8F91;&#x662F;&#x5224;&#x65AD;informer&#x662F;&#x5426;&#x5DF2;&#x7ECF;&#x5411;factory&#x6CE8;&#x518C;&#x5B8C;&#x6210;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x5219;&#x8FDB;&#x884C;&#x6CE8;&#x518C;&#x64CD;&#x4F5C;&#x3002;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>sharedInformerFactory<span class="token punctuation">)</span> <span class="token function">InformerFor</span><span class="token punctuation">(</span>obj runtime<span class="token punctuation">.</span>Object<span class="token punctuation">,</span> newFunc internalinterfaces<span class="token punctuation">.</span>NewInformerFunc<span class="token punctuation">)</span> 
cache<span class="token punctuation">.</span>SharedIndexInformer <span class="token punctuation">{</span>
    f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">defer</span> f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

    informerType <span class="token operator">:=</span> reflect<span class="token punctuation">.</span><span class="token function">TypeOf</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span>
    informer<span class="token punctuation">,</span> exists <span class="token operator">:=</span> f<span class="token punctuation">.</span>informers<span class="token punctuation">[</span>informerType<span class="token punctuation">]</span>
    <span class="token keyword">if</span> exists <span class="token punctuation">{</span>
        <span class="token keyword">return</span> informer
    <span class="token punctuation">}</span>

    resyncPeriod<span class="token punctuation">,</span> exists <span class="token operator">:=</span> f<span class="token punctuation">.</span>customResync<span class="token punctuation">[</span>informerType<span class="token punctuation">]</span>
    <span class="token keyword">if</span> <span class="token operator">!</span>exists <span class="token punctuation">{</span>
        resyncPeriod <span class="token operator">=</span> f<span class="token punctuation">.</span>defaultResync
    <span class="token punctuation">}</span>

    informer <span class="token operator">=</span> <span class="token function">newFunc</span><span class="token punctuation">(</span>f<span class="token punctuation">.</span>client<span class="token punctuation">,</span> resyncPeriod<span class="token punctuation">)</span>
    f<span class="token punctuation">.</span>informers<span class="token punctuation">[</span>informerType<span class="token punctuation">]</span> <span class="token operator">=</span> informer

    <span class="token keyword">return</span> informer
<span class="token punctuation">}</span>
</code></pre>
<h4 id="43-informer-run"><a name="43-informer-run" class="anchor-navigation-ex-anchor" href="#43-informer-run"><i class="fa fa-link" aria-hidden="true"></i></a>4.3 Informer Run</h4>
<p>&#x6700;&#x7EC8;informerFactory&#x5C06;&#x6CE8;&#x518C;&#x5230;&#x5DE5;&#x5382;&#x7684;&#x6240;&#x6709;informer&#x90FD;&#x542F;&#x52A8;,Informer&#x4E3B;&#x8981;&#x7684;&#x5DE5;&#x4F5C;&#x5C31;&#x662F;&#x76D1;&#x542C;&#x4E8B;&#x4EF6;&#xFF0C;&#x5E76;&#x5206;&#x53D1;&#x4E8B;&#x4EF6;&#x3002;</p>
<pre class="language-"><code class="lang-go"><span class="token comment">// Start initializes all requested informers.</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>sharedInformerFactory<span class="token punctuation">)</span> <span class="token function">Start</span><span class="token punctuation">(</span>stopCh <span class="token operator">&lt;-</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">defer</span> f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

    <span class="token keyword">for</span> informerType<span class="token punctuation">,</span> informer <span class="token operator">:=</span> <span class="token keyword">range</span> f<span class="token punctuation">.</span>informers <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token operator">!</span>f<span class="token punctuation">.</span>startedInformers<span class="token punctuation">[</span>informerType<span class="token punctuation">]</span> <span class="token punctuation">{</span>
            <span class="token keyword">go</span> informer<span class="token punctuation">.</span><span class="token function">Run</span><span class="token punctuation">(</span>stopCh<span class="token punctuation">)</span>
            f<span class="token punctuation">.</span>startedInformers<span class="token punctuation">[</span>informerType<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token boolean">true</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x800C;WaitForCacheSync&#x7684;&#x4F5C;&#x7528;&#x4E3B;&#x8981;&#x662F;&#x786E;&#x8BA4;&#x662F;&#x5426;&#x6240;&#x6709;&#x7684;Informer&#x7684;&#x90FD;&#x5DF2;&#x7ECF;&#x4ECE;kubernetes&#x63A5;&#x6536;&#x8FC7;&#x4E8B;&#x4EF6;&#xFF0C;&#x5982;&#x679C;&#x5DF2;&#x7ECF;&#x63A5;&#x6536;&#x5230;&#x4E8B;&#x4EF6;&#xFF0C;&#x90A3;&#x4E48;HasSynced&#x4F1A;&#x88AB;&#x8BBE;&#x7F6E;&#x4E3A;true</p>
<pre class="language-"><code class="lang-go"><span class="token comment">// WaitForCacheSync waits for all started informers&apos; cache were synced.</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>sharedInformerFactory<span class="token punctuation">)</span> <span class="token function">WaitForCacheSync</span><span class="token punctuation">(</span>stopCh <span class="token operator">&lt;-</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span><span class="token builtin">bool</span> <span class="token punctuation">{</span>
    informers <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span>cache<span class="token punctuation">.</span>SharedIndexInformer <span class="token punctuation">{</span>
        f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">defer</span> f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

        informers <span class="token operator">:=</span> <span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span>cache<span class="token punctuation">.</span>SharedIndexInformer<span class="token punctuation">{</span><span class="token punctuation">}</span>
        <span class="token keyword">for</span> informerType<span class="token punctuation">,</span> informer <span class="token operator">:=</span> <span class="token keyword">range</span> f<span class="token punctuation">.</span>informers <span class="token punctuation">{</span>
            <span class="token keyword">if</span> f<span class="token punctuation">.</span>startedInformers<span class="token punctuation">[</span>informerType<span class="token punctuation">]</span> <span class="token punctuation">{</span>
                informers<span class="token punctuation">[</span>informerType<span class="token punctuation">]</span> <span class="token operator">=</span> informer
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> informers
    <span class="token punctuation">}</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

    res <span class="token operator">:=</span> <span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span><span class="token builtin">bool</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token keyword">for</span> informType<span class="token punctuation">,</span> informer <span class="token operator">:=</span> <span class="token keyword">range</span> informers <span class="token punctuation">{</span>
        res<span class="token punctuation">[</span>informType<span class="token punctuation">]</span> <span class="token operator">=</span> cache<span class="token punctuation">.</span><span class="token function">WaitForCacheSync</span><span class="token punctuation">(</span>stopCh<span class="token punctuation">,</span> informer<span class="token punctuation">.</span>HasSynced<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> res
<span class="token punctuation">}</span>
</code></pre>
<h4 id="44-sharedindexinformer"><a name="44-sharedindexinformer" class="anchor-navigation-ex-anchor" href="#44-sharedindexinformer"><i class="fa fa-link" aria-hidden="true"></i></a>4.4 sharedIndexInformer</h4>
<p>informer&#x4F5C;&#x4E3A;&#x5F02;&#x6B65;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x6846;&#x67B6;&#xFF0C;&#x5B8C;&#x6210;&#x4E86;&#x4E8B;&#x4EF6;&#x76D1;&#x542C;&#x548C;&#x5206;&#x53D1;&#x5904;&#x7406;&#x4E24;&#x4E2A;&#x8FC7;&#x7A0B;&#xFF0C;sharedIndexInformer&#x7684;&#x58F0;&#x660E;&#x7ED3;&#x6784;&#xFF0C;&#x8BE5;&#x7ED3;&#x6784;&#x5C31;&#x662F;&#x4EE3;&#x8868;&#x4E86;&#x4E00;&#x4E2A;Informer&#x5B9E;&#x4F8B;&#x3002;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">type</span> sharedIndexInformer <span class="token keyword">struct</span> <span class="token punctuation">{</span>
    indexer               Indexer
    controller            Controller

    processor             <span class="token operator">*</span>sharedProcessor
    cacheMutationDetector CacheMutationDetector

    <span class="token comment">// This block is tracked to handle late initialization of the controller</span>
    listerWatcher ListerWatcher
    objectType    runtime<span class="token punctuation">.</span>Object

    <span class="token comment">// resyncCheckPeriod is how often we want the reflector&apos;s resync timer to fire so it can call</span>
    <span class="token comment">// shouldResync to check if any of our listeners need a resync.</span>
    resyncCheckPeriod time<span class="token punctuation">.</span>Duration
    <span class="token comment">// defaultEventHandlerResyncPeriod is the default resync period for any handlers added via</span>
    <span class="token comment">// AddEventHandler (i.e. they don&apos;t specify one and just want to use the shared informer&apos;s default</span>
    <span class="token comment">// value).</span>
    defaultEventHandlerResyncPeriod time<span class="token punctuation">.</span>Duration
    <span class="token comment">// clock allows for testability</span>
    clock clock<span class="token punctuation">.</span>Clock

    started<span class="token punctuation">,</span> stopped <span class="token builtin">bool</span>
    startedLock      sync<span class="token punctuation">.</span>Mutex

    <span class="token comment">// blockDeltas gives a way to stop all event distribution so that a late event handler</span>
    <span class="token comment">// can safely join the shared informer.</span>
    blockDeltas sync<span class="token punctuation">.</span>Mutex
<span class="token punctuation">}</span>
</code></pre>
<p>&#x9996;&#x5148;&#x6765;&#x770B;indexer&#x6210;&#x5458;&#xFF0C;&#x8BE5;&#x6210;&#x5458;indexer&#x662F;&#x4E00;&#x4E2A;&#x4FDD;&#x5B58;&#x5168;&#x91CF;&#x6570;&#x636E;&#x7684;&#x7F13;&#x5B58;Store&#x3002; Informer&#x5BF9;&#x5916;&#x63D0;&#x4F9B;&#x7684;Lister&#x5C31;&#x662F;&#x76F4;&#x63A5;&#x4ECE;Store&#x83B7;&#x53D6;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x800C;&#x6CA1;&#x6709;&#x76F4;&#x63A5;&#x64CD;&#x4F5C;etcd&#x3002;</p>
<h4 id="45-indexer&#x7684;&#x58F0;&#x660E;&#x7ED3;&#x6784;"><a name="45-indexer&#x7684;&#x58F0;&#x660E;&#x7ED3;&#x6784;" class="anchor-navigation-ex-anchor" href="#45-indexer&#x7684;&#x58F0;&#x660E;&#x7ED3;&#x6784;"><i class="fa fa-link" aria-hidden="true"></i></a>4.5 indexer&#x7684;&#x58F0;&#x660E;&#x7ED3;&#x6784;:</h4>
<pre class="language-"><code class="lang-go"><span class="token comment">// Indexer is a storage interface that lets you list objects using multiple indexing functions</span>
<span class="token keyword">type</span> Indexer <span class="token keyword">interface</span> <span class="token punctuation">{</span>
    Store
    math
    <span class="token function">Index</span><span class="token punctuation">(</span>indexName <span class="token builtin">string</span><span class="token punctuation">,</span> obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span>
    math
    <span class="token function">IndexKeys</span><span class="token punctuation">(</span>indexName<span class="token punctuation">,</span> indexKey <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span>
    <span class="token comment">// ListIndexFuncValues returns the list of generated values of an Index func</span>
    <span class="token function">ListIndexFuncValues</span><span class="token punctuation">(</span>indexName <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">string</span>
    math
    <span class="token function">ByIndex</span><span class="token punctuation">(</span>indexName<span class="token punctuation">,</span> indexKey <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span>
    <span class="token comment">// GetIndexer return the indexers</span>
    <span class="token function">GetIndexers</span><span class="token punctuation">(</span><span class="token punctuation">)</span> Indexers

    <span class="token comment">// AddIndexers adds more indexers to this store.  If you call this after you already have data</span>
    <span class="token comment">// in the store, the results are undefined.</span>
    <span class="token function">AddIndexers</span><span class="token punctuation">(</span>newIndexers Indexers<span class="token punctuation">)</span> <span class="token builtin">error</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4E0B;&#x9762;&#x8FD9;&#x4E2A;&#x4EE3;&#x7801;&#x7247;&#x6BB5;&#x662F;&#x542F;&#x52A8;&#x4E00;&#x4E2A;Informer&#x5B9E;&#x4F8B;&#xFF0C;&#x9700;&#x8981;&#x505A;&#x7684;&#x5904;&#x7406;&#x903B;&#x8F91;&#x3002;&#x63A5;&#x4E0B;&#x6765;&#xFF0C;&#x8BA9;&#x6211;&#x4EEC;&#x5206;&#x6790;&#x4E0B;&#x8FD9;&#x90E8;&#x5206;&#x5904;&#x7406;&#x903B;&#x8F91;&#x7684;&#x5404;&#x4E2A;&#x7EC6;&#x8282;&#x90E8;&#x5206;&#x3002;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>s <span class="token operator">*</span>sharedIndexInformer<span class="token punctuation">)</span> <span class="token function">Run</span><span class="token punctuation">(</span>stopCh <span class="token operator">&lt;-</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">defer</span> utilruntime<span class="token punctuation">.</span><span class="token function">HandleCrash</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

    fifo <span class="token operator">:=</span> <span class="token function">NewDeltaFIFO</span><span class="token punctuation">(</span>MetaNamespaceKeyFunc<span class="token punctuation">,</span> s<span class="token punctuation">.</span>indexer<span class="token punctuation">)</span>

    cfg <span class="token operator">:=</span> <span class="token operator">&amp;</span>Config<span class="token punctuation">{</span>
        Queue<span class="token punctuation">:</span>            fifo<span class="token punctuation">,</span>
        ListerWatcher<span class="token punctuation">:</span>    s<span class="token punctuation">.</span>listerWatcher<span class="token punctuation">,</span>
        ObjectType<span class="token punctuation">:</span>       s<span class="token punctuation">.</span>objectType<span class="token punctuation">,</span>
        FullResyncPeriod<span class="token punctuation">:</span> s<span class="token punctuation">.</span>resyncCheckPeriod<span class="token punctuation">,</span>
        RetryOnError<span class="token punctuation">:</span>     <span class="token boolean">false</span><span class="token punctuation">,</span>
        ShouldResync<span class="token punctuation">:</span>     s<span class="token punctuation">.</span>processor<span class="token punctuation">.</span>shouldResync<span class="token punctuation">,</span>

        Process<span class="token punctuation">:</span> s<span class="token punctuation">.</span>HandleDeltas<span class="token punctuation">,</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        s<span class="token punctuation">.</span>startedLock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">defer</span> s<span class="token punctuation">.</span>startedLock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

        s<span class="token punctuation">.</span>controller <span class="token operator">=</span> <span class="token function">New</span><span class="token punctuation">(</span>cfg<span class="token punctuation">)</span>
        s<span class="token punctuation">.</span>controller<span class="token punctuation">.</span><span class="token punctuation">(</span><span class="token operator">*</span>controller<span class="token punctuation">)</span><span class="token punctuation">.</span>clock <span class="token operator">=</span> s<span class="token punctuation">.</span>clock
        s<span class="token punctuation">.</span>started <span class="token operator">=</span> <span class="token boolean">true</span>
    <span class="token punctuation">}</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

    <span class="token comment">// Separate stop channel because Processor should be stopped strictly after controller</span>
    processorStopCh <span class="token operator">:=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token keyword">var</span> wg wait<span class="token punctuation">.</span>Group
    <span class="token keyword">defer</span> wg<span class="token punctuation">.</span><span class="token function">Wait</span><span class="token punctuation">(</span><span class="token punctuation">)</span>              <span class="token comment">// Wait for Processor to stop</span>
    <span class="token keyword">defer</span> <span class="token function">close</span><span class="token punctuation">(</span>processorStopCh<span class="token punctuation">)</span> <span class="token comment">// Tell Processor to stop</span>
    wg<span class="token punctuation">.</span><span class="token function">StartWithChannel</span><span class="token punctuation">(</span>processorStopCh<span class="token punctuation">,</span> s<span class="token punctuation">.</span>cacheMutationDetector<span class="token punctuation">.</span>Run<span class="token punctuation">)</span>
    wg<span class="token punctuation">.</span><span class="token function">StartWithChannel</span><span class="token punctuation">(</span>processorStopCh<span class="token punctuation">,</span> s<span class="token punctuation">.</span>processor<span class="token punctuation">.</span>run<span class="token punctuation">)</span>

    <span class="token keyword">defer</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        s<span class="token punctuation">.</span>startedLock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">defer</span> s<span class="token punctuation">.</span>startedLock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        s<span class="token punctuation">.</span>stopped <span class="token operator">=</span> <span class="token boolean">true</span> <span class="token comment">// Don&apos;t want any new listeners</span>
    <span class="token punctuation">}</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    s<span class="token punctuation">.</span>controller<span class="token punctuation">.</span><span class="token function">Run</span><span class="token punctuation">(</span>stopCh<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
<h4 id="46-deltafifo"><a name="46-deltafifo" class="anchor-navigation-ex-anchor" href="#46-deltafifo"><i class="fa fa-link" aria-hidden="true"></i></a>4.6 DeltaFIFO</h4>
<p>&#x9996;&#x5148;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;DeltaFIFO&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#xFF0C;&#x8BE5;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x7684;&#x58F0;&#x660E;&#x7ED3;&#x6784;:</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">type</span> DeltaFIFO <span class="token keyword">struct</span> <span class="token punctuation">{</span>
    <span class="token comment">// lock/cond protects access to &apos;items&apos; and &apos;queue&apos;.</span>
    lock sync<span class="token punctuation">.</span>RWMutex
    cond sync<span class="token punctuation">.</span>Cond

    <span class="token comment">// We depend on the property that items in the set are in</span>
    <span class="token comment">// the queue and vice versa, and that all Deltas in this</span>
    <span class="token comment">// map have at least one Delta.</span>
    items <span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">string</span><span class="token punctuation">]</span>Deltas
    queue <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">string</span>

    <span class="token comment">// populated is true if the first batch of items inserted by Replace() has been populated</span>
    <span class="token comment">// or Delete/Add/Update was called first.</span>
    populated <span class="token builtin">bool</span>
    <span class="token comment">// initialPopulationCount is the number of items inserted by the first call of Replace()</span>
    initialPopulationCount <span class="token builtin">int</span>

    <span class="token comment">// keyFunc is used to make the key used for queued item</span>
    <span class="token comment">// insertion and retrieval, and should be deterministic.</span>
    keyFunc KeyFunc

    <span class="token comment">// knownObjects list keys that are &quot;known&quot;, for the</span>
    <span class="token comment">// purpose of figuring out which items have been deleted</span>
    <span class="token comment">// when Replace() or Delete() is called.</span>
    knownObjects KeyListerGetter

    <span class="token comment">// Indication the queue is closed.</span>
    <span class="token comment">// Used to indicate a queue is closed so a control loop can exit when a queue is empty.</span>
    <span class="token comment">// Currently, not used to gate any of CRED operations.</span>
    closed     <span class="token builtin">bool</span>
    closedLock sync<span class="token punctuation">.</span>Mutex
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5728;Informer&#x4E2D;,DeltaFIFO&#x4F5C;&#x4E3A;Reflector&#x7684;Store,&#x6839;&#x636E;List/Watch&#x7684;&#x7ED3;&#x679C;&#x5BF9;Store&#x8FDB;&#x884C;ADD,UPDATE,DELETE&#x64CD;&#x4F5C;&#x3002;&#x5728;Delta&#x7684;&#x58F0;&#x660E;&#x7ED3;&#x6784;&#x4E2D;&#xFF0C;
&#x6700;&#x91CD;&#x8981;&#x7684;&#x5C31;&#x662F;&#x4E24;&#x4E2A;&#x6210;&#x5458;iterms&#x548C;queue&#x3002;iterms&#x6210;&#x5458;&#x7F13;&#x5B58;&#x4E86;&#x6240;&#x6709;&#x6DFB;&#x52A0;&#x5230;Store&#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#xFF0C;&#x800C;queue&#x5219;&#x5B58;&#x50A8;&#x8FD9;&#x4E9B;&#x4E8B;&#x4EF6;&#x7684;id&#x4F5C;&#x4E3A;FIFO&#x5904;&#x7406;&#x7684;&#x5148;&#x540E;&#x987A;&#x5E8F;&#x3002;
&#x800C;populated&#x548C;initialPopulationCount&#x4E24;&#x4E2A;&#x6210;&#x5458;&#x4E3B;&#x8981;&#x5F53;Store&#x88AB;&#x9996;&#x6B21;&#x521D;&#x59CB;&#x5316;&#x5B8C;&#x6210;&#x4E4B;&#x540E;&#xFF0C;&#x4F1A;&#x88AB;&#x8BBE;&#x7F6E;&#x4E3A;true&#x3002;</p>
<p>iterms&#x7684;&#x58F0;&#x660E;&#x7ED3;&#x6784;:</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">const</span> <span class="token punctuation">(</span>
    Added   DeltaType <span class="token operator">=</span> <span class="token string">&quot;Added&quot;</span>
    Updated DeltaType <span class="token operator">=</span> <span class="token string">&quot;Updated&quot;</span>
    Deleted DeltaType <span class="token operator">=</span> <span class="token string">&quot;Deleted&quot;</span>
    <span class="token comment">// The other types are obvious. You&apos;ll get Sync deltas when:</span>
    <span class="token comment">//  * A watch expires/errors out and a new list/watch cycle is started.</span>
    <span class="token comment">//  * You&apos;ve turned on periodic syncs.</span>
    <span class="token comment">// (Anything that trigger&apos;s DeltaFIFO&apos;s Replace() method.)</span>
    Sync DeltaType <span class="token operator">=</span> <span class="token string">&quot;Sync&quot;</span>
<span class="token punctuation">)</span>

<span class="token comment">// Delta is the type stored by a DeltaFIFO. It tells you what change</span>
<span class="token comment">// happened, and the object&apos;s state after* that change.</span>
<span class="token comment">//</span>
<span class="token comment">// [*] Unless the change is a deletion, and then you&apos;ll get the final</span>
<span class="token comment">//     state of the object before it was deleted.</span>
<span class="token keyword">type</span> Delta <span class="token keyword">struct</span> <span class="token punctuation">{</span>
    Type   DeltaType
    Object <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">// Deltas is a list of one or more &apos;Delta&apos;s to an individual object.</span>
<span class="token comment">// The oldest delta is at index 0, the newest delta is the last one.</span>
<span class="token keyword">type</span> Deltas <span class="token punctuation">[</span><span class="token punctuation">]</span>Delta
</code></pre>
<h3 id="47-controller"><a name="47-controller" class="anchor-navigation-ex-anchor" href="#47-controller"><i class="fa fa-link" aria-hidden="true"></i></a>4.7 Controller</h3>
<p>&#x5F53;&#x521D;&#x59CB;&#x5316;DeltaFIFO&#x5B9E;&#x4F8B;&#x4E4B;&#x540E;&#xFF0C;&#x5C31;&#x5BF9;controller&#x7684;Config&#x8FDB;&#x884C;&#x521D;&#x59CB;&#x5316;&#x64CD;&#x4F5C;,Config&#x7684;&#x58F0;&#x660E;&#x7ED3;&#x6784;:</p>
<pre class="language-"><code class="lang-go"><span class="token comment">// Config contains all the settings for a Controller.</span>
<span class="token keyword">type</span> Config <span class="token keyword">struct</span> <span class="token punctuation">{</span>
    <span class="token comment">// The queue for your objects - has to be a DeltaFIFO due to</span>
    <span class="token comment">// assumptions in the implementation. Your Process() function</span>
    <span class="token comment">// should accept the output of this Queue&apos;s Pop() method.</span>
    Queue

    <span class="token comment">// Something that can list and watch your objects.</span>
    ListerWatcher

    <span class="token comment">// Something that can process your objects.</span>
    Process ProcessFunc

    <span class="token comment">// The type of your objects.</span>
    ObjectType runtime<span class="token punctuation">.</span>Object

    <span class="token comment">// Reprocess everything at least this often.</span>
    <span class="token comment">// Note that if it takes longer for you to clear the queue than this</span>
    <span class="token comment">// period, you will end up processing items in the order determined</span>
    <span class="token comment">// by FIFO.Replace(). Currently, this is random. If this is a</span>
    <span class="token comment">// problem, we can change that replacement policy to append new</span>
    <span class="token comment">// things to the end of the queue instead of replacing the entire</span>
    <span class="token comment">// queue.</span>
    FullResyncPeriod time<span class="token punctuation">.</span>Duration

    <span class="token comment">// ShouldResync, if specified, is invoked when the controller&apos;s reflector determines the next</span>
    <span class="token comment">// periodic sync should occur. If this returns true, it means the reflector should proceed with</span>
    <span class="token comment">// the resync.</span>
    ShouldResync ShouldResyncFunc

    <span class="token comment">// If true, when Process() returns an error, re-enqueue the object.</span>
    <span class="token comment">// TODO: add interface to let you inject a delay/backoff or drop</span>
    <span class="token comment">//       the object completely if desired. Pass the object in</span>
    <span class="token comment">//       question to this interface as a parameter.</span>
    RetryOnError <span class="token builtin">bool</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5BF9;Config&#x4E2D;&#x7684;&#x4E3B;&#x8981;&#x6210;&#x5458;&#x8FDB;&#x884C;&#x4ECB;&#x7ECD;&#x4E0B;&#xFF0C;&#x65B9;&#x4FBF;&#x4E4B;&#x540E;&#x4ECB;&#x7ECD;controller&#x7684;&#x65F6;&#x5019;&#x65B9;&#x4FBF;&#x4E86;&#x89E3;&#x3002;</p>
<ul>
<li>Queue: DeltaFIFO&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x961F;&#x5217;&#xFF0C;&#x4E4B;&#x540E;Queue&#x7684;POP&#x65B9;&#x6CD5;&#x4F1A;&#x4ECE;&#x8BE5;&#x961F;&#x5217;&#x4E2D;&#x4E0D;&#x65AD;&#x7684;POP&#x6570;&#x636E;&#x7ED9;Process()&#x65B9;&#x6CD5;&#x53BB;&#x5904;&#x7406;&#x3002;</li>
<li>ListerWatcher: &#x7528;&#x4E8E;List/Watch&#x5173;&#x5FC3;&#x7684;kubernetes&#x8D44;&#x6E90;&#x5BF9;&#x8C61;&#x3002;</li>
<li>Process: &#x5C31;&#x662F;&#x5904;&#x7406;&#x4ECE;DeltaFIFO&#x4E2D;POP&#x51FA;&#x6765;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x8FD9;&#x4E2A;&#x5177;&#x4F53;&#x7684;&#x5B9E;&#x73B0;&#x540E;&#x7EED;&#x4F1A;&#x4ECB;&#x7ECD;&#x5230;&#x3002;
&#x6700;&#x7EC8;&#x5BF9;Config&#x521D;&#x59CB;&#x5316;&#x5B8C;&#x6210;&#x4E4B;&#x540E;&#xFF0C;&#x8D4B;&#x503C;&#x7ED9;sharedIndexInformer&#x7684;controller&#x6210;&#x5458;&#x3002;</li>
</ul>
<p>Controller&#x7684;Run&#x4E3B;&#x8981;&#x662F;&#x4E00;&#x4E2A;&#x751F;&#x4EA7;&#x8005;&#x6D88;&#x8D39;&#x8005;&#x6A21;&#x5F0F;&#xFF0C;reflector&#x662F;&#x751F;&#x4EA7;&#x8005;&#xFF0C;&#x4E3A;controller&#x4E2D;&#x7684;Process&#x65B9;&#x6CD5;Process: 
s.HandleDeltas&#x662F;&#x6D88;&#x8D39;&#x8005;&#x3002;&#x800C;processLoop&#x4F1A;&#x5FAA;&#x73AF;&#x7684;&#x4ECE;Queue(DeltaFIFO)&#x4E2D;POP&#x4E8B;&#x4EF6;&#x6570;&#x636E;&#x7ED9;s.HandleDeltas&#x53BB;&#x5904;&#x7406;&#x3002;</p>
<p>Controller Run&#x7684;&#x4EE3;&#x7801;&#x7247;&#x6BB5;&#x5982;&#x4E0B;:</p>
<pre class="language-"><code class="lang-go"><span class="token comment">// Run begins processing items, and will continue until a value is sent down stopCh.</span>
<span class="token comment">// It&apos;s an error to call Run more than once.</span>
<span class="token comment">// Run blocks; call via go.</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>c <span class="token operator">*</span>controller<span class="token punctuation">)</span> <span class="token function">Run</span><span class="token punctuation">(</span>stopCh <span class="token operator">&lt;-</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">defer</span> utilruntime<span class="token punctuation">.</span><span class="token function">HandleCrash</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">go</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token operator">&lt;-</span>stopCh
        c<span class="token punctuation">.</span>config<span class="token punctuation">.</span>Queue<span class="token punctuation">.</span><span class="token function">Close</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    r <span class="token operator">:=</span> <span class="token function">NewReflector</span><span class="token punctuation">(</span>
        c<span class="token punctuation">.</span>config<span class="token punctuation">.</span>ListerWatcher<span class="token punctuation">,</span>
        c<span class="token punctuation">.</span>config<span class="token punctuation">.</span>ObjectType<span class="token punctuation">,</span>
        c<span class="token punctuation">.</span>config<span class="token punctuation">.</span>Queue<span class="token punctuation">,</span>
        c<span class="token punctuation">.</span>config<span class="token punctuation">.</span>FullResyncPeriod<span class="token punctuation">,</span>
    <span class="token punctuation">)</span>
    r<span class="token punctuation">.</span>ShouldResync <span class="token operator">=</span> c<span class="token punctuation">.</span>config<span class="token punctuation">.</span>ShouldResync
    r<span class="token punctuation">.</span>clock <span class="token operator">=</span> c<span class="token punctuation">.</span>clock

    c<span class="token punctuation">.</span>reflectorMutex<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    c<span class="token punctuation">.</span>reflector <span class="token operator">=</span> r
    c<span class="token punctuation">.</span>reflectorMutex<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

    <span class="token keyword">var</span> wg wait<span class="token punctuation">.</span>Group
    <span class="token keyword">defer</span> wg<span class="token punctuation">.</span><span class="token function">Wait</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

    wg<span class="token punctuation">.</span><span class="token function">StartWithChannel</span><span class="token punctuation">(</span>stopCh<span class="token punctuation">,</span> r<span class="token punctuation">.</span>Run<span class="token punctuation">)</span>

    wait<span class="token punctuation">.</span><span class="token function">Until</span><span class="token punctuation">(</span>c<span class="token punctuation">.</span>processLoop<span class="token punctuation">,</span> time<span class="token punctuation">.</span>Second<span class="token punctuation">,</span> stopCh<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5728;&#x4E0A;&#x9762;&#x7684;&#x8FD9;&#x6BB5;&#x4EE3;&#x7801;&#x7247;&#x6BB5;&#x4E2D;&#xFF0C;&#x9996;&#x5148;&#x4F1A;&#x5148;&#x542F;&#x52A8;reflector&#x6765;List/Watch&#x6211;&#x4EEC;&#x6240;&#x5173;&#x5FC3;&#x7684;&#x8D44;&#x6E90;&#xFF0C;&#x5E76;&#x5C06;&#x5176;&#x6DFB;&#x52A0;&#x5230;Store(DeltaFIFO)&#x4E2D;&#x3002;&#x5177;&#x4F53;&#x7684;&#x5B9E;&#x73B0;&#x903B;&#x8F91;&#x5982;&#x4E0B;:</p>
<pre class="language-"><code class="lang-go"><span class="token comment">// Reflector watches a specified resource and causes all changes to be reflected in the given store.</span>
<span class="token keyword">type</span> Reflector <span class="token keyword">struct</span> <span class="token punctuation">{</span>
    <span class="token comment">// name identifies this reflector. By default it will be a file:line if possible.</span>
    name <span class="token builtin">string</span>
    <span class="token comment">// metrics tracks basic metric information about the reflector</span>
    metrics <span class="token operator">*</span>reflectorMetrics

    <span class="token comment">// The type of object we expect to place in the store.</span>
    expectedType reflect<span class="token punctuation">.</span>Type
    <span class="token comment">// The destination to sync up with the watch source</span>
    store Store
    <span class="token comment">// listerWatcher is used to perform lists and watches.</span>
    listerWatcher ListerWatcher
    <span class="token comment">// period controls timing between one watch ending and</span>
    <span class="token comment">// the beginning of the next one.</span>
    period       time<span class="token punctuation">.</span>Duration
    resyncPeriod time<span class="token punctuation">.</span>Duration
    ShouldResync <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">bool</span>
    <span class="token comment">// clock allows tests to manipulate time</span>
    clock clock<span class="token punctuation">.</span>Clock
    <span class="token comment">// lastSyncResourceVersion is the resource version token last</span>
    <span class="token comment">// observed when doing a sync with the underlying store</span>
    <span class="token comment">// it is thread safe, but not synchronized with the underlying store</span>
    lastSyncResourceVersion <span class="token builtin">string</span>
    <span class="token comment">// lastSyncResourceVersionMutex guards read/write access to lastSyncResourceVersion</span>
    lastSyncResourceVersionMutex sync<span class="token punctuation">.</span>RWMutex
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5BF9;Reflector&#x5BF9;&#x8C61;&#x7684;&#x521D;&#x59CB;&#x5316;&#x903B;&#x8F91;&#x5982;&#x4E0B;:</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token function">NewReflector</span><span class="token punctuation">(</span>lw ListerWatcher<span class="token punctuation">,</span> expectedType <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> store Store<span class="token punctuation">,</span> resyncPeriod time<span class="token punctuation">.</span>Duration<span class="token punctuation">)</span> <span class="token operator">*</span>Reflector <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">NewNamedReflector</span><span class="token punctuation">(</span>naming<span class="token punctuation">.</span><span class="token function">GetNameFromCallsite</span><span class="token punctuation">(</span>internalPackages<span class="token operator">...</span><span class="token punctuation">)</span><span class="token punctuation">,</span> lw<span class="token punctuation">,</span> expectedType<span class="token punctuation">,</span> store<span class="token punctuation">,</span> resyncPeriod<span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// NewNamedReflector same as NewReflector, but with a specified name for logging</span>
<span class="token keyword">func</span> <span class="token function">NewNamedReflector</span><span class="token punctuation">(</span>name <span class="token builtin">string</span><span class="token punctuation">,</span> lw ListerWatcher<span class="token punctuation">,</span> expectedType <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> store Store<span class="token punctuation">,</span> resyncPeriod time<span class="token punctuation">.</span>Duration<span class="token punctuation">)</span> <span class="token operator">*</span>Reflector <span class="token punctuation">{</span>
    reflectorSuffix <span class="token operator">:=</span> atomic<span class="token punctuation">.</span><span class="token function">AddInt64</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>reflectorDisambiguator<span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span>
    r <span class="token operator">:=</span> <span class="token operator">&amp;</span>Reflector<span class="token punctuation">{</span>
        name<span class="token punctuation">:</span> name<span class="token punctuation">,</span>
        <span class="token comment">// we need this to be unique per process (some names are still the same) but obvious who it belongs to</span>
        metrics<span class="token punctuation">:</span>       <span class="token function">newReflectorMetrics</span><span class="token punctuation">(</span><span class="token function">makeValidPrometheusMetricLabel</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">&quot;reflector_&quot;</span><span class="token operator">+</span>name<span class="token operator">+</span><span class="token string">&quot;_%d&quot;</span><span class="token punctuation">,</span> reflectorSuffix<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        listerWatcher<span class="token punctuation">:</span> lw<span class="token punctuation">,</span>
        store<span class="token punctuation">:</span>         store<span class="token punctuation">,</span>
        expectedType<span class="token punctuation">:</span>  reflect<span class="token punctuation">.</span><span class="token function">TypeOf</span><span class="token punctuation">(</span>expectedType<span class="token punctuation">)</span><span class="token punctuation">,</span>
        period<span class="token punctuation">:</span>        time<span class="token punctuation">.</span>Second<span class="token punctuation">,</span>
        resyncPeriod<span class="token punctuation">:</span>  resyncPeriod<span class="token punctuation">,</span>
        clock<span class="token punctuation">:</span>         <span class="token operator">&amp;</span>clock<span class="token punctuation">.</span>RealClock<span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> r
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5F53;Reflector&#x521D;&#x59CB;&#x5316;&#x5B8C;&#x6210;&#x4E4B;&#x540E;&#xFF0C;&#x5219;&#x542F;&#x52A8;Reflector&#x6765;&#x8BA9;&#x5B83;&#x53BB;&#x5E2E;&#x52A9;&#x4F60;&#x53BB;List/Watch&#x5DE5;&#x4F5C;&#x3002;&#x5177;&#x4F53;&#x7684;&#x542F;&#x52A8;&#x5B9E;&#x73B0;&#x903B;&#x8F91;&#x5982;&#x4E0B;:</p>
<pre class="language-"><code class="lang-go"><span class="token comment">// Run starts a watch and handles watch events. Will restart the watch if it is closed.</span>
<span class="token comment">// Run will exit when stopCh is closed.</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>r <span class="token operator">*</span>Reflector<span class="token punctuation">)</span> <span class="token function">Run</span><span class="token punctuation">(</span>stopCh <span class="token operator">&lt;-</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    klog<span class="token punctuation">.</span><span class="token function">V</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Infof</span><span class="token punctuation">(</span><span class="token string">&quot;Starting reflector %v (%s) from %s&quot;</span><span class="token punctuation">,</span> r<span class="token punctuation">.</span>expectedType<span class="token punctuation">,</span> r<span class="token punctuation">.</span>resyncPeriod<span class="token punctuation">,</span> r<span class="token punctuation">.</span>name<span class="token punctuation">)</span>
    wait<span class="token punctuation">.</span><span class="token function">Until</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> err <span class="token operator">:=</span> r<span class="token punctuation">.</span><span class="token function">ListAndWatch</span><span class="token punctuation">(</span>stopCh<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
            utilruntime<span class="token punctuation">.</span><span class="token function">HandleError</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span> r<span class="token punctuation">.</span>period<span class="token punctuation">,</span> stopCh<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x8FD9;&#x6BB5;&#x4EE3;&#x7801;&#x7684;&#x6838;&#x5FC3;&#x5C31;&#x662F;&#x901A;&#x8FC7;r.ListAndWatch&#x65B9;&#x6CD5;&#x53BB;List/Watch&#x3002;&#x7531;&#x4E8E;r.ListAndWatch&#x5B9E;&#x73B0;&#x903B;&#x8F91;&#x592A;&#x957F;&#xFF0C;&#x5C31;&#x7B80;&#x5355;&#x7684;&#x8BF4;&#x4E0B;&#x5B83;&#x7684;&#x5B9E;&#x73B0;&#x903B;&#x8F91;,&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x4E3B;&#x8981;&#x505A;&#x4E24;&#x4EF6;&#x4E8B;&#x513F;:</p>
<ul>
<li>list&#x6240;&#x6709;&#x5173;&#x5FC3;&#x7684;&#x8D44;&#x6E90;&#x5BF9;&#x8C61;&#xFF0C;&#x5E76;&#x5C06;&#x5BF9;&#x8C61;&#x5B58;&#x50A8;&#x5230;Store&#x4E2D;&#x3002;</li>
<li>watch&#x6240;&#x5173;&#x5FC3;&#x7684;&#x8D44;&#x6E90;&#x5BF9;&#x8C61;, &#x5E76;&#x5224;&#x65AD;&#x5BF9;&#x8C61;&#x662F;&#x5426;&#x5DF2;&#x7ECF;&#x5B58;&#x5728;Store,&#x5982;&#x679C;&#x5B58;&#x5728;&#x5219;UPDATE,&#x5426;&#x5219;&#x6DFB;&#x52A0;&#xFF0C;&#x6216;&#x8005;&#x5220;&#x9664;&#x3002;</li>
<li>ok,&#x8FD9;&#x6837;&#x73B0;&#x5728;&#x901A;&#x8FC7;Reflector&#x8FD9;&#x4E2A;&#x751F;&#x4EA7;&#x8005;&#xFF0C;&#x6211;&#x4EEC;&#x5C31;&#x628A;&#x6211;&#x4EEC;&#x6240;&#x5173;&#x5FC3;&#x7684;&#x8D44;&#x6E90;&#x5BF9;&#x8C61;&#x6DFB;&#x52A0;&#x5230;Store(DeltaFIFO)&#x4E2D;&#x4E86;&#x3002;&#x63A5;&#x4E0B;&#x6765;&#x901A;&#x8FC7;&#x6211;&#x4EEC;&#x7684;Process&#x65B9;&#x6CD5;&#x6765;&#x4ECE;Queue&#x4E2D;POP&#x51FA;&#x4E8B;&#x4EF6;&#x6570;&#x636E;&#xFF0C;&#x8FDB;&#x884C;&#x6D88;&#x8D39;&#x5904;&#x7406;&#x3002;</li>
</ul>
<p>processLoop&#x7684;&#x5904;&#x7406;&#x903B;&#x8F91;&#x4EE3;&#x7801;&#x7247;&#x6BB5;&#x5982;&#x4E0B;:</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>c <span class="token operator">*</span>controller<span class="token punctuation">)</span> <span class="token function">processLoop</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">for</span> <span class="token punctuation">{</span>
        obj<span class="token punctuation">,</span> err <span class="token operator">:=</span> c<span class="token punctuation">.</span>config<span class="token punctuation">.</span>Queue<span class="token punctuation">.</span><span class="token function">Pop</span><span class="token punctuation">(</span><span class="token function">PopProcessFunc</span><span class="token punctuation">(</span>c<span class="token punctuation">.</span>config<span class="token punctuation">.</span>Process<span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
            <span class="token keyword">if</span> err <span class="token operator">==</span> FIFOClosedError <span class="token punctuation">{</span>
                <span class="token keyword">return</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">if</span> c<span class="token punctuation">.</span>config<span class="token punctuation">.</span>RetryOnError <span class="token punctuation">{</span>
                <span class="token comment">// This is the safe way to re-enqueue.</span>
                c<span class="token punctuation">.</span>config<span class="token punctuation">.</span>Queue<span class="token punctuation">.</span><span class="token function">AddIfNotPresent</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>process&#x4F1A;&#x4E0D;&#x65AD;&#x7684;&#x4ECE;Queue&#x4E2D;POP&#x4E8B;&#x4EF6;&#x6570;&#x636E;&#x7ED9;c.config.Process&#x6D88;&#x8D39;&#x3002;&#x5982;&#x679C;&#x5728;&#x6D88;&#x8D39;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#x51FA;&#x73B0;&#x9519;&#x8BEF;&#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x5219;&#x8FD8;&#x4F1A;&#x91CD;&#x65B0;&#x7684;&#x628A;&#x6570;&#x636E;&#x91CD;&#x65B0;&#x52A0;&#x56DE;&#x5230;queue&#x961F;&#x5217;&#x4E2D;&#x3002;</p>
<p>queue.POP&#x65B9;&#x6CD5;&#x7684;&#x5B9E;&#x73B0;&#x903B;&#x8F91;&#x5982;&#x4E0B;:</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>DeltaFIFO<span class="token punctuation">)</span> <span class="token function">Pop</span><span class="token punctuation">(</span>process PopProcessFunc<span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">defer</span> f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">for</span> <span class="token punctuation">{</span>
        <span class="token keyword">for</span> <span class="token function">len</span><span class="token punctuation">(</span>f<span class="token punctuation">.</span>queue<span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">0</span> <span class="token punctuation">{</span>
            <span class="token comment">// When the queue is empty, invocation of Pop() is blocked until new item is enqueued.</span>
            <span class="token comment">// When Close() is called, the f.closed is set and the condition is broadcasted.</span>
            <span class="token comment">// Which causes this loop to continue and return from the Pop().</span>
            <span class="token keyword">if</span> f<span class="token punctuation">.</span><span class="token function">IsClosed</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">return</span> <span class="token boolean">nil</span><span class="token punctuation">,</span> FIFOClosedError
            <span class="token punctuation">}</span>

            f<span class="token punctuation">.</span>cond<span class="token punctuation">.</span><span class="token function">Wait</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token punctuation">}</span>
        id <span class="token operator">:=</span> f<span class="token punctuation">.</span>queue<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span>
        f<span class="token punctuation">.</span>queue <span class="token operator">=</span> f<span class="token punctuation">.</span>queue<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">:</span><span class="token punctuation">]</span>
        <span class="token keyword">if</span> f<span class="token punctuation">.</span>initialPopulationCount <span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token punctuation">{</span>
            f<span class="token punctuation">.</span>initialPopulationCount<span class="token operator">--</span>
        <span class="token punctuation">}</span>
        item<span class="token punctuation">,</span> ok <span class="token operator">:=</span> f<span class="token punctuation">.</span>items<span class="token punctuation">[</span>id<span class="token punctuation">]</span>
        <span class="token keyword">if</span> <span class="token operator">!</span>ok <span class="token punctuation">{</span>
            <span class="token comment">// Item may have been deleted subsequently.</span>
            <span class="token keyword">continue</span>
        <span class="token punctuation">}</span>
        <span class="token function">delete</span><span class="token punctuation">(</span>f<span class="token punctuation">.</span>items<span class="token punctuation">,</span> id<span class="token punctuation">)</span>
        err <span class="token operator">:=</span> <span class="token function">process</span><span class="token punctuation">(</span>item<span class="token punctuation">)</span>
        <span class="token keyword">if</span> e<span class="token punctuation">,</span> ok <span class="token operator">:=</span> err<span class="token punctuation">.</span><span class="token punctuation">(</span>ErrRequeue<span class="token punctuation">)</span><span class="token punctuation">;</span> ok <span class="token punctuation">{</span>
            f<span class="token punctuation">.</span><span class="token function">addIfNotPresent</span><span class="token punctuation">(</span>id<span class="token punctuation">,</span> item<span class="token punctuation">)</span>
            err <span class="token operator">=</span> e<span class="token punctuation">.</span>Err
        <span class="token punctuation">}</span>
        <span class="token comment">// Don&apos;t need to copyDeltas here, because we&apos;re transferring</span>
        <span class="token comment">// ownership to the caller.</span>
        <span class="token keyword">return</span> item<span class="token punctuation">,</span> err
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>c.config.Process(&#x5C31;&#x662F;HandleDeltas)&#x65B9;&#x6CD5;&#x7684;&#x5904;&#x7406;&#x903B;&#x8F91;&#x5982;&#x4E0B;:</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>s <span class="token operator">*</span>sharedIndexInformer<span class="token punctuation">)</span> <span class="token function">HandleDeltas</span><span class="token punctuation">(</span>obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
    s<span class="token punctuation">.</span>blockDeltas<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">defer</span> s<span class="token punctuation">.</span>blockDeltas<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

    <span class="token comment">// from oldest to newest</span>
    <span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> d <span class="token operator">:=</span> <span class="token keyword">range</span> obj<span class="token punctuation">.</span><span class="token punctuation">(</span>Deltas<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">switch</span> d<span class="token punctuation">.</span>Type <span class="token punctuation">{</span>
        <span class="token keyword">case</span> Sync<span class="token punctuation">,</span> Added<span class="token punctuation">,</span> Updated<span class="token punctuation">:</span>
            isSync <span class="token operator">:=</span> d<span class="token punctuation">.</span>Type <span class="token operator">==</span> Sync
            s<span class="token punctuation">.</span>cacheMutationDetector<span class="token punctuation">.</span><span class="token function">AddObject</span><span class="token punctuation">(</span>d<span class="token punctuation">.</span>Object<span class="token punctuation">)</span>
            <span class="token keyword">if</span> old<span class="token punctuation">,</span> exists<span class="token punctuation">,</span> err <span class="token operator">:=</span> s<span class="token punctuation">.</span>indexer<span class="token punctuation">.</span><span class="token function">Get</span><span class="token punctuation">(</span>d<span class="token punctuation">.</span>Object<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token operator">&amp;&amp;</span> exists <span class="token punctuation">{</span>
                <span class="token keyword">if</span> err <span class="token operator">:=</span> s<span class="token punctuation">.</span>indexer<span class="token punctuation">.</span><span class="token function">Update</span><span class="token punctuation">(</span>d<span class="token punctuation">.</span>Object<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
                    <span class="token keyword">return</span> err
                <span class="token punctuation">}</span>
                s<span class="token punctuation">.</span>processor<span class="token punctuation">.</span><span class="token function">distribute</span><span class="token punctuation">(</span>updateNotification<span class="token punctuation">{</span>oldObj<span class="token punctuation">:</span> old<span class="token punctuation">,</span> newObj<span class="token punctuation">:</span> d<span class="token punctuation">.</span>Object<span class="token punctuation">}</span><span class="token punctuation">,</span> isSync<span class="token punctuation">)</span>
            <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
                <span class="token keyword">if</span> err <span class="token operator">:=</span> s<span class="token punctuation">.</span>indexer<span class="token punctuation">.</span><span class="token function">Add</span><span class="token punctuation">(</span>d<span class="token punctuation">.</span>Object<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
                    <span class="token keyword">return</span> err
                <span class="token punctuation">}</span>
                s<span class="token punctuation">.</span>processor<span class="token punctuation">.</span><span class="token function">distribute</span><span class="token punctuation">(</span>addNotification<span class="token punctuation">{</span>newObj<span class="token punctuation">:</span> d<span class="token punctuation">.</span>Object<span class="token punctuation">}</span><span class="token punctuation">,</span> isSync<span class="token punctuation">)</span>
            <span class="token punctuation">}</span>
        <span class="token keyword">case</span> Deleted<span class="token punctuation">:</span>
            <span class="token keyword">if</span> err <span class="token operator">:=</span> s<span class="token punctuation">.</span>indexer<span class="token punctuation">.</span><span class="token function">Delete</span><span class="token punctuation">(</span>d<span class="token punctuation">.</span>Object<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
                <span class="token keyword">return</span> err
            <span class="token punctuation">}</span>
            s<span class="token punctuation">.</span>processor<span class="token punctuation">.</span><span class="token function">distribute</span><span class="token punctuation">(</span>deleteNotification<span class="token punctuation">{</span>oldObj<span class="token punctuation">:</span> d<span class="token punctuation">.</span>Object<span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> <span class="token boolean">nil</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x6BCF;&#x5F53;&#x4ECE;Queue&#x961F;&#x5217;&#x4E2D;POP&#x51FA;&#x65B0;&#x7684;&#x4E8B;&#x4EF6;&#x6570;&#x636E;&#x65F6;&#xFF0C;&#x90FD;&#x4F1A;&#x88AB;&#x4E0A;&#x9762;&#x7684;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x5904;&#x7406;&#xFF0C;&#x9996;&#x5148;&#x4F1A;&#x6839;&#x636E;&#x5143;&#x7D20;&#x7684;&#x5904;&#x7406;&#x7C7B;&#x578B;,&#x6765;&#x51B3;&#x5B9A;&#x5177;&#x4F53;&#x7684;&#x5904;&#x7406;&#x903B;&#x8F91;:</p>
<p>&#x4E0B;&#x9762;&#x662F;&#x6BCF;&#x4E2A;&#x4E8B;&#x4EF6;&#x5143;&#x7D20;&#x80FD;&#x591F;&#x88AB;&#x5904;&#x7406;&#x7684;&#x65F6;&#x95F4;&#x7C7B;&#x578B;:</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">const</span> <span class="token punctuation">(</span>
    Added   DeltaType <span class="token operator">=</span> <span class="token string">&quot;Added&quot;</span>
    Updated DeltaType <span class="token operator">=</span> <span class="token string">&quot;Updated&quot;</span>
    Deleted DeltaType <span class="token operator">=</span> <span class="token string">&quot;Deleted&quot;</span>
    <span class="token comment">// The other types are obvious. You&apos;ll get Sync deltas when:</span>
    <span class="token comment">//  * A watch expires/errors out and a new list/watch cycle is started.</span>
    <span class="token comment">//  * You&apos;ve turned on periodic syncs.</span>
    <span class="token comment">// (Anything that trigger&apos;s DeltaFIFO&apos;s Replace() method.)</span>
    Sync DeltaType <span class="token operator">=</span> <span class="token string">&quot;Sync&quot;</span>
<span class="token punctuation">)</span>
</code></pre>
<p>&#x5982;&#x679C;&#x662F;Sync,ADD,Updated,DELETE&#x5219;&#x76F8;&#x5E94;&#x7684;&#x5904;&#x7406;&#x903B;&#x8F91;&#x5982;&#x4E0B;:</p>
<p>1.&#x5982;&#x679C;&#x662F;ADD&#x7C7B;&#x578B;&#xFF0C;&#x5219;&#x76F4;&#x63A5;&#x5C06;&#x65B0;&#x6DFB;&#x52A0;&#x7684;&#x5143;&#x7D20;ADD&#x5230;Store&#x4E2D;&#xFF0C;&#x4E4B;&#x540E;&#x8FDB;&#x884C;&#x4E8B;&#x4EF6;&#x7684;&#x5206;&#x53D1;distribute&#x64CD;&#x4F5C;&#x3002;
2.&#x5982;&#x679C;&#x662F;UPDATED&#x7C7B;&#x578B;&#xFF0C;&#x5219;&#x4ECE;Store&#x4E2D;&#x83B7;&#x53D6;&#x8BE5;&#x5143;&#x7D20;&#xFF0C;&#x5E76;&#x66F4;&#x65B0;Store&#x4E2D;&#x7684;&#x5143;&#x7D20;&#xFF0C;&#x4E4B;&#x540E;&#x8FDB;&#x884C;&#x4E8B;&#x4EF6;&#x7684;&#x5206;&#x53D1;distribute&#x64CD;&#x4F5C;&#x3002;
3.&#x5982;&#x679C;&#x662F;DELETE&#x7C7B;&#x578B;&#xFF0C;&#x5219;&#x76F4;&#x63A5;&#x4ECE;Store&#x4E2D;&#x5220;&#x9664;&#x5143;&#x7D20;&#xFF0C;&#x4E4B;&#x540E;&#x4E5F;&#x662F;&#x8FDB;&#x884C;&#x4E8B;&#x4EF6;&#x7684;&#x5206;&#x53D1;distribute&#x64CD;&#x4F5C;&#x3002;</p>
<p>sharedProcessor
&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x5728;&#x5BF9;sharedProcessor&#x7684;&#x4E8B;&#x4EF6;&#x5206;&#x53D1;&#x5904;&#x7406;&#x8FDB;&#x884C;&#x8BE6;&#x7EC6;&#x7684;&#x4ECB;&#x7ECD;&#x3002;&#x5728;&#x6D88;&#x8D39;&#x4E8B;&#x4EF6;&#x65F6;&#xFF0C;&#x901A;&#x8FC7;informer&#x7684;processer&#x8FDB;&#x884C;distrubute&#x3002;processer&#x8FDB;&#x884C;&#x5206;&#x53D1;&#x7684;&#x5904;&#x7406;&#x51FD;&#x6570;&#x7531;&#x5916;&#x90E8;&#x7684;AddEventHandler&#x5411;processer&#x91CC;addListener&#x3002;&#x5176;&#x4E2D;addListener&#x53EA;&#x662F;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;processer&#x7BA1;&#x7406;listeners,&#x5E76;&#x5728;&#x5206;&#x53D1;&#x65F6;&#x904D;&#x5386;listeners&#xFF0C;&#x5C06;&#x4E8B;&#x4EF6;&#x53D1;&#x9001;&#x7ED9;&#x6240;&#x6709;&#x7684;listener&#x3002;</p>
<p>sharedProcessor&#x7684;&#x58F0;&#x660E;&#x7ED3;&#x6784;&#x5982;&#x4E0B;:</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">type</span> sharedProcessor <span class="token keyword">struct</span> <span class="token punctuation">{</span>
    listenersStarted <span class="token builtin">bool</span>
    listenersLock    sync<span class="token punctuation">.</span>RWMutex
    listeners        <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">*</span>processorListener
    syncingListeners <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">*</span>processorListener
    clock            clock<span class="token punctuation">.</span>Clock
    wg               wait<span class="token punctuation">.</span>Group
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token punctuation">(</span>p <span class="token operator">*</span>sharedProcessor<span class="token punctuation">)</span> <span class="token function">addListener</span><span class="token punctuation">(</span>listener <span class="token operator">*</span>processorListener<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    p<span class="token punctuation">.</span>listenersLock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">defer</span> p<span class="token punctuation">.</span>listenersLock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

    p<span class="token punctuation">.</span><span class="token function">addListenerLocked</span><span class="token punctuation">(</span>listener<span class="token punctuation">)</span>
    <span class="token keyword">if</span> p<span class="token punctuation">.</span>listenersStarted <span class="token punctuation">{</span>
        p<span class="token punctuation">.</span>wg<span class="token punctuation">.</span><span class="token function">Start</span><span class="token punctuation">(</span>listener<span class="token punctuation">.</span>run<span class="token punctuation">)</span>
        p<span class="token punctuation">.</span>wg<span class="token punctuation">.</span><span class="token function">Start</span><span class="token punctuation">(</span>listener<span class="token punctuation">.</span>pop<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token punctuation">(</span>p <span class="token operator">*</span>sharedProcessor<span class="token punctuation">)</span> <span class="token function">distribute</span><span class="token punctuation">(</span>obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> sync <span class="token builtin">bool</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    p<span class="token punctuation">.</span>listenersLock<span class="token punctuation">.</span><span class="token function">RLock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">defer</span> p<span class="token punctuation">.</span>listenersLock<span class="token punctuation">.</span><span class="token function">RUnlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

    <span class="token keyword">if</span> sync <span class="token punctuation">{</span>
        <span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> listener <span class="token operator">:=</span> <span class="token keyword">range</span> p<span class="token punctuation">.</span>syncingListeners <span class="token punctuation">{</span>
            listener<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
        <span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> listener <span class="token operator">:=</span> <span class="token keyword">range</span> p<span class="token punctuation">.</span>listeners <span class="token punctuation">{</span>
            listener<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>processor&#x7684;run&#x4FDD;&#x8BC1;&#x6240;&#x6709;listener&#x90FD;&#x5F00;&#x59CB;&#x8FD0;&#x884C;&#xFF0C;&#x5E76;&#x4FDD;&#x8BC1;&#x9000;&#x51FA;&#x65F6;&#x6240;&#x6709;listener&#x7684;chan&#x90FD;&#x5173;&#x95ED;&#x3002;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>p <span class="token operator">*</span>sharedProcessor<span class="token punctuation">)</span> <span class="token function">run</span><span class="token punctuation">(</span>stopCh <span class="token operator">&lt;-</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        p<span class="token punctuation">.</span>listenersLock<span class="token punctuation">.</span><span class="token function">RLock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">defer</span> p<span class="token punctuation">.</span>listenersLock<span class="token punctuation">.</span><span class="token function">RUnlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> listener <span class="token operator">:=</span> <span class="token keyword">range</span> p<span class="token punctuation">.</span>listeners <span class="token punctuation">{</span>
            p<span class="token punctuation">.</span>wg<span class="token punctuation">.</span><span class="token function">Start</span><span class="token punctuation">(</span>listener<span class="token punctuation">.</span>run<span class="token punctuation">)</span>
            p<span class="token punctuation">.</span>wg<span class="token punctuation">.</span><span class="token function">Start</span><span class="token punctuation">(</span>listener<span class="token punctuation">.</span>pop<span class="token punctuation">)</span>
        <span class="token punctuation">}</span>
        p<span class="token punctuation">.</span>listenersStarted <span class="token operator">=</span> <span class="token boolean">true</span>
    <span class="token punctuation">}</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token operator">&lt;-</span>stopCh
    p<span class="token punctuation">.</span>listenersLock<span class="token punctuation">.</span><span class="token function">RLock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">defer</span> p<span class="token punctuation">.</span>listenersLock<span class="token punctuation">.</span><span class="token function">RUnlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> listener <span class="token operator">:=</span> <span class="token keyword">range</span> p<span class="token punctuation">.</span>listeners <span class="token punctuation">{</span>
        <span class="token function">close</span><span class="token punctuation">(</span>listener<span class="token punctuation">.</span>addCh<span class="token punctuation">)</span> <span class="token comment">// Tell .pop() to stop. .pop() will tell .run() to stop</span>
    <span class="token punctuation">}</span>
    p<span class="token punctuation">.</span>wg<span class="token punctuation">.</span><span class="token function">Wait</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// Wait for all .pop() and .run() to stop</span>
<span class="token punctuation">}</span>
</code></pre>
<p>processorListener</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">type</span> processorListener <span class="token keyword">struct</span> <span class="token punctuation">{</span>
    nextCh <span class="token keyword">chan</span> <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
    addCh  <span class="token keyword">chan</span> <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span>

    handler ResourceEventHandler

    <span class="token comment">// pendingNotifications is an unbounded ring buffer that holds all notifications not yet distributed.</span>
    <span class="token comment">// There is one per listener, but a failing/stalled listener will have infinite pendingNotifications</span>
    <span class="token comment">// added until we OOM.</span>
    <span class="token comment">// TODO: This is no worse than before, since reflectors were backed by unbounded DeltaFIFOs, but</span>
    <span class="token comment">// we should try to do something better.</span>
    pendingNotifications buffer<span class="token punctuation">.</span>RingGrowing

    <span class="token comment">// requestedResyncPeriod is how frequently the listener wants a full resync from the shared informer</span>
    requestedResyncPeriod time<span class="token punctuation">.</span>Duration
    <span class="token comment">// resyncPeriod is how frequently the listener wants a full resync from the shared informer. This</span>
    <span class="token comment">// value may differ from requestedResyncPeriod if the shared informer adjusts it to align with the</span>
    <span class="token comment">// informer&apos;s overall resync check period.</span>
    resyncPeriod time<span class="token punctuation">.</span>Duration
    <span class="token comment">// nextResync is the earliest time the listener should get a full resync</span>
    nextResync time<span class="token punctuation">.</span>Time
    <span class="token comment">// resyncLock guards access to resyncPeriod and nextResync</span>
    resyncLock sync<span class="token punctuation">.</span>Mutex
<span class="token punctuation">}</span>
</code></pre>
<p>pendingNotifications&#x88C5;&#x4E86;&#x6240;&#x6709;&#x8FD8;&#x6CA1;&#x5206;&#x53D1;&#x7684;&#x4E8B;&#x4EF6;&#x3002;&#x800C;handler&#x5219;&#x662F;&#x5F00;&#x53D1;&#x8005;&#x5411;Informer&#x6CE8;&#x518C;&#x7684;ResourceEventHandler</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">type</span> processorListener <span class="token keyword">struct</span> <span class="token punctuation">{</span>
    nextCh <span class="token keyword">chan</span> <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
    addCh  <span class="token keyword">chan</span> <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span>

    handler ResourceEventHandler

    <span class="token comment">// pendingNotifications is an unbounded ring buffer that holds all notifications not yet distributed.</span>
    <span class="token comment">// There is one per listener, but a failing/stalled listener will have infinite pendingNotifications</span>
    <span class="token comment">// added until we OOM.</span>
    <span class="token comment">// TODO: This is no worse than before, since reflectors were backed by unbounded DeltaFIFOs, but</span>
    <span class="token comment">// we should try to do something better.</span>
    pendingNotifications buffer<span class="token punctuation">.</span>RingGrowing

    <span class="token comment">// requestedResyncPeriod is how frequently the listener wants a full resync from the shared informer</span>
    requestedResyncPeriod time<span class="token punctuation">.</span>Duration
    <span class="token comment">// resyncPeriod is how frequently the listener wants a full resync from the shared informer. This</span>
    <span class="token comment">// value may differ from requestedResyncPeriod if the shared informer adjusts it to align with the</span>
    <span class="token comment">// informer&apos;s overall resync check period.</span>
    resyncPeriod time<span class="token punctuation">.</span>Duration
    <span class="token comment">// nextResync is the earliest time the listener should get a full resync</span>
    nextResync time<span class="token punctuation">.</span>Time
    <span class="token comment">// resyncLock guards access to resyncPeriod and nextResync</span>
    resyncLock sync<span class="token punctuation">.</span>Mutex
<span class="token punctuation">}</span>
</code></pre>
<p>pendingNotifications&#x88C5;&#x4E86;&#x6240;&#x6709;&#x8FD8;&#x6CA1;&#x5206;&#x53D1;&#x7684;&#x4E8B;&#x4EF6;&#x3002;&#x800C;handler&#x5219;&#x662F;&#x5F00;&#x53D1;&#x8005;&#x5411;Informer&#x6CE8;&#x518C;&#x7684;ResourceEventHandler&#x3002;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">type</span> ResourceEventHandler <span class="token keyword">interface</span> <span class="token punctuation">{</span>
    <span class="token function">OnAdd</span><span class="token punctuation">(</span>obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token function">OnUpdate</span><span class="token punctuation">(</span>oldObj<span class="token punctuation">,</span> newObj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token function">OnDelete</span><span class="token punctuation">(</span>obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x800C;ResourceEventHandler&#x8FD9;&#x4E2A;&#x63A5;&#x53E3;&#x88AB;ResourceEventHandlerFuncs&#x7ED3;&#x6784;&#x5DF2;&#x7ECF;&#x5B9E;&#x73B0;&#x4E86;&#xFF0C;&#x5F00;&#x53D1;&#x8005;&#x53BB;&#x5B9E;&#x73B0;&#x4E0B;&#x9762;&#x7684;AddFunc,
 UpdateFunc, DeleteFunc&#x5E76;&#x6CE8;&#x518C;&#x5230;Informer&#x5373;&#x53EF;&#x3002;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">type</span> ResourceEventHandlerFuncs <span class="token keyword">struct</span> <span class="token punctuation">{</span>
    AddFunc    <span class="token keyword">func</span><span class="token punctuation">(</span>obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
    UpdateFunc <span class="token keyword">func</span><span class="token punctuation">(</span>oldObj<span class="token punctuation">,</span> newObj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
    DeleteFunc <span class="token keyword">func</span><span class="token punctuation">(</span>obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x63A5;&#x4E0B;&#x6765;&#x7EE7;&#x7EED;&#xFF0C;&#x5176;&#x4E2D;&#x5904;&#x7406;&#x4E8B;&#x4EF6;processor&#x5F00;&#x59CB;distribute&#x65F6;&#xFF0C;&#x4F1A;&#x8C03;&#x7528;listener&#x7684;add&#x65B9;&#x6CD5;&#xFF0C;&#x5C06;&#x4E8B;&#x4EF6;&#x53D1;&#x5230;addCh&#x4E0A;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>p <span class="token operator">*</span>processorListener<span class="token punctuation">)</span> <span class="token function">add</span><span class="token punctuation">(</span>notification <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    p<span class="token punctuation">.</span>addCh <span class="token operator">&lt;-</span> notification
<span class="token punctuation">}</span>
</code></pre>
<p>listener&#x7684;pop goroutine&#x4E0D;&#x65AD;&#x5730;&#x4ECE;addCh&#x4E2D;&#x83B7;&#x53D6;&#x4E8B;&#x4EF6;&#xFF0C;&#x5199;&#x5230;&#x672C;&#x5730;&#x7684;pendingNotification&#x6216;&#x5199;&#x7ED9;nextCh&#xFF0C;&#x800C;nextCh&#x4ECE;&#x672C;&#x5730;pendingNotification&#x6216;addCh&#x83B7;&#x53D6;&#x4E8B;&#x4EF6;&#x3002;&#x6700;&#x540E;&#x7531;run&#x65B9;&#x6CD5;&#x6D88;&#x8D39;&#x4E8B;&#x4EF6;&#x548C;&#x5206;&#x53D1;&#x4E8B;&#x4EF6;&#x3002;run&#x65B9;&#x6CD5;&#x652F;&#x6301;&#x6307;&#x6570;&#x91CD;&#x8BD5;&#xFF0C;&#x9000;&#x51FA;&#x4E5F;&#x4F1A;&#x91CD;&#x65B0;&#x5F00;&#x59CB;&#x3002;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>p <span class="token operator">*</span>processorListener<span class="token punctuation">)</span> <span class="token function">pop</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">defer</span> utilruntime<span class="token punctuation">.</span><span class="token function">HandleCrash</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">defer</span> <span class="token function">close</span><span class="token punctuation">(</span>p<span class="token punctuation">.</span>nextCh<span class="token punctuation">)</span> <span class="token comment">// Tell .run() to stop</span>

    <span class="token keyword">var</span> nextCh <span class="token keyword">chan</span><span class="token operator">&lt;-</span> <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token keyword">var</span> notification <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token keyword">for</span> <span class="token punctuation">{</span>
        <span class="token keyword">select</span> <span class="token punctuation">{</span>
        <span class="token keyword">case</span> nextCh <span class="token operator">&lt;-</span> notification<span class="token punctuation">:</span>
            <span class="token comment">// Notification dispatched</span>
            <span class="token keyword">var</span> ok <span class="token builtin">bool</span>
            notification<span class="token punctuation">,</span> ok <span class="token operator">=</span> p<span class="token punctuation">.</span>pendingNotifications<span class="token punctuation">.</span><span class="token function">ReadOne</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token keyword">if</span> <span class="token operator">!</span>ok <span class="token punctuation">{</span> <span class="token comment">// Nothing to pop</span>
                nextCh <span class="token operator">=</span> <span class="token boolean">nil</span> <span class="token comment">// Disable this select case</span>
            <span class="token punctuation">}</span>
        <span class="token keyword">case</span> notificationToAdd<span class="token punctuation">,</span> ok <span class="token operator">:=</span> <span class="token operator">&lt;-</span>p<span class="token punctuation">.</span>addCh<span class="token punctuation">:</span>
            <span class="token keyword">if</span> <span class="token operator">!</span>ok <span class="token punctuation">{</span>
                <span class="token keyword">return</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">if</span> notification <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span> <span class="token comment">// No notification to pop (and pendingNotifications is empty)</span>
                <span class="token comment">// Optimize the case - skip adding to pendingNotifications</span>
                notification <span class="token operator">=</span> notificationToAdd
                nextCh <span class="token operator">=</span> p<span class="token punctuation">.</span>nextCh
            <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> <span class="token comment">// There is already a notification waiting to be dispatched</span>
                p<span class="token punctuation">.</span>pendingNotifications<span class="token punctuation">.</span><span class="token function">WriteOne</span><span class="token punctuation">(</span>notificationToAdd<span class="token punctuation">)</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token punctuation">(</span>p <span class="token operator">*</span>processorListener<span class="token punctuation">)</span> <span class="token function">run</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// this call blocks until the channel is closed.  When a panic happens during the notification</span>
    <span class="token comment">// we will catch it, **the offending item will be skipped!**, and after a short delay (one second)</span>
    <span class="token comment">// the next notification will be attempted.  This is usually better than the alternative of never</span>
    <span class="token comment">// delivering again.</span>
    stopCh <span class="token operator">:=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
    wait<span class="token punctuation">.</span><span class="token function">Until</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// this gives us a few quick retries before a long pause and then a few more quick retries</span>
        err <span class="token operator">:=</span> wait<span class="token punctuation">.</span><span class="token function">ExponentialBackoff</span><span class="token punctuation">(</span>retry<span class="token punctuation">.</span>DefaultRetry<span class="token punctuation">,</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token builtin">bool</span><span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">for</span> next <span class="token operator">:=</span> <span class="token keyword">range</span> p<span class="token punctuation">.</span>nextCh <span class="token punctuation">{</span>
                <span class="token keyword">switch</span> notification <span class="token operator">:=</span> next<span class="token punctuation">.</span><span class="token punctuation">(</span><span class="token keyword">type</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">case</span> updateNotification<span class="token punctuation">:</span>
                    p<span class="token punctuation">.</span>handler<span class="token punctuation">.</span><span class="token function">OnUpdate</span><span class="token punctuation">(</span>notification<span class="token punctuation">.</span>oldObj<span class="token punctuation">,</span> notification<span class="token punctuation">.</span>newObj<span class="token punctuation">)</span>
                <span class="token keyword">case</span> addNotification<span class="token punctuation">:</span>
                    p<span class="token punctuation">.</span>handler<span class="token punctuation">.</span><span class="token function">OnAdd</span><span class="token punctuation">(</span>notification<span class="token punctuation">.</span>newObj<span class="token punctuation">)</span>
                <span class="token keyword">case</span> deleteNotification<span class="token punctuation">:</span>
                    p<span class="token punctuation">.</span>handler<span class="token punctuation">.</span><span class="token function">OnDelete</span><span class="token punctuation">(</span>notification<span class="token punctuation">.</span>oldObj<span class="token punctuation">)</span>
                <span class="token keyword">default</span><span class="token punctuation">:</span>
                    utilruntime<span class="token punctuation">.</span><span class="token function">HandleError</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;unrecognized notification: %#v&quot;</span><span class="token punctuation">,</span> next<span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span>
            <span class="token comment">// the only way to get here is if the p.nextCh is empty and closed</span>
            <span class="token keyword">return</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token boolean">nil</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span>

        <span class="token comment">// the only way to get here is if the p.nextCh is empty and closed</span>
        <span class="token keyword">if</span> err <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
            <span class="token function">close</span><span class="token punctuation">(</span>stopCh<span class="token punctuation">)</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token operator">*</span>time<span class="token punctuation">.</span>Minute<span class="token punctuation">,</span> stopCh<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x8FD9;&#x6837;&#x5C31;&#x5BF9;Store&#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x4E86;&#x5206;&#x53D1;&#xFF0C;&#x5982;&#x679C;&#x5F00;&#x53D1;&#x8005;&#x60F3;&#x8981;&#x5B9E;&#x73B0;&#x81EA;&#x5DF1;&#x7684;custom controller&#x7684;&#x8BDD;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x5206;&#x53D1;&#x4E4B;&#x540E;&#xFF0C;
&#x5C06;&#x5206;&#x53D1;&#x540E;&#x7684;&#x6570;&#x636E;&#x5199;&#x5165;&#x5230;client-go&#x63D0;&#x4F9B;&#x7684;Workqueue&#x961F;&#x5217;&#x4E2D;&#xFF0C;&#x5E76;&#x5728;&#x81EA;&#x5DF1;&#x5B9E;&#x73B0;&#x7684;syncHandler&#x5B9E;&#x73B0;&#x903B;&#x8F91;&#x4E2D;&#x4E0D;&#x65AD;&#x7684;&#x4E2D;Workqueue&#x4E2D;&#x53BB;&#x83B7;&#x53D6;key,&#x7136;&#x540E;&#x53BB;&#x5B9E;&#x73B0;&#x81EA;&#x5DF1;&#x7684;&#x903B;&#x8F91;&#x3002;</p>
<h4 id="link"><a name="link" class="anchor-navigation-ex-anchor" href="#link"><i class="fa fa-link" aria-hidden="true"></i></a>Link</h4>
<ul>
<li><p><a href="https://zhuanlan.zhihu.com/p/59660536" target="_blank">https://zhuanlan.zhihu.com/p/59660536</a></p>
</li>
<li><p><a href="https://xigang.github.io/2019/09/21/client-go/" target="_blank">&#x539F;&#x6587; Kubernetes Client-Go Informer &#x5B9E;&#x73B0;&#x6E90;&#x7801;&#x5256;&#x6790;</a></p>
</li>
<li><a href="https://www.cnblogs.com/maoqide/p/11254937.html" target="_blank">&#x81EA;&#x5DF1;&#x6784;&#x5EFA;&#x4E00;&#x4E2A; k8s sample-controller.</a></li>
<li><a href="https://blog.openshift.com/kubernetes-deep-dive-code-generation-customresources/" target="_blank">Kubernetes Deep Dive: Code Generation for CustomResources</a></li>
<li><a href="https://blog.csdn.net/weixin_42663840/article/details/81980022" target="_blank">&#x6DF1;&#x5165;&#x6D45;&#x51FA;kubernetes&#x4E4B;client-go&#x7684;SharedInformerFactory</a></li>
<li><a href="https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/" target="_blank">kubernetes.io/crd</a></li>
</ul>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; caixisheng 2017 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2021-04-10 01:41:29
</span></footer> <link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css"> <script>     window.klipse_settings = {         selector: ".language-klipse, .lang-eval-clojure",         selector_eval_js: ".lang-eval-js",         selector_eval_python_client: ".lang-eval-python",         selector_eval_php: ".lang-eval-php",         selector_eval_scheme: ".lang-eval-scheme",         selector_eval_ruby: ".lang-eval-ruby",         selector_reagent: ".lang-reagent",        selector_google_charts: ".lang-google-chart",        selector_es2017: ".lang-eval-es2017",        selector_jsx: ".lang-eval-jsx",        selector_transpile_jsx: ".lang-transpile-jsx",        selector_render_jsx: ".lang-render-jsx",        selector_react: ".lang-react",        selector_eval_markdown: ".lang-render-markdown",        selector_eval_lambdaway: ".lang-render-lambdaway",        selector_eval_cpp: ".lang-eval-cpp",        selector_eval_html: ".lang-render-html",        selector_sql: ".lang-eval-sql",        selector_brainfuck: "lang-eval-brainfuck",        selector_js: ".lang-transpile-cljs"    }; </script> <script src="https://storage.googleapis.com/app.klipse.tech/plugin/js/klipse_plugin.js"></script>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="command.html" class="navigation navigation-prev " aria-label="Previous page: Command">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="copy docker config.html" class="navigation navigation-next " aria-label="Next page: Copy Docker Config">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Controller","level":"1.9.11","depth":2,"next":{"title":"Copy Docker Config","level":"1.9.12","depth":2,"path":"blog/kubernetes/copy docker config.md","ref":"blog/kubernetes/copy docker config.md","articles":[]},"previous":{"title":"Command","level":"1.9.10","depth":2,"path":"blog/kubernetes/command.md","ref":"blog/kubernetes/command.md","articles":[]},"dir":"ltr"},"config":{"plugins":["summary","expandable-chapters","toggle-chapters","theme-comscore","-lunr","-search","-highlight","-livereload","search-plus@^0.0.11","simple-page-toc@^0.1.1","github@^2.0.0","github-buttons@2.1.0","edit-link@^2.0.2","disqus@^0.1.0","prism@^2.1.0","prism-themes@^0.0.2","advanced-emoji@^0.2.1","anchors@^0.7.1","include-codeblock@^3.0.2","emphasize@^1.1.0","katex@^1.1.3","splitter@^0.0.8","mermaid-gb3@2.1.0","tbfed-pagefooter@^0.0.1","expandable-chapters-small@^0.1.7","sectionx@^3.1.0","donate@^1.0.2","local-video@^1.0.1","anchor-navigation-ex@0.1.8","favicon@^0.0.2","3-ba@^0.9.0","terminal@^0.3.2","alerts@^0.2.0","include-csv@^0.1.0","puml@^1.0.1","musicxml@^1.0.2","klipse@^1.2.0","versions-select@^0.1.1","-sharing","sharing-plus@^0.0.2","graph@^0.1.0","chart@^0.2.0"],"root":".","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright © caixisheng 2017","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"prism":{"css":["prism-themes/themes/prism-base16-ateliersulphurpool.light.css"]},"include-csv":{},"disqus":{"useIdentifier":false,"shortName":"gitbookuse"},"emphasize":{},"github":{"url":"https://github.com/xishengcai/xisheng.blog"},"puml":{},"simple-page-toc":{"maxDepth":3,"skipFirstH1":true},"summary":{},"splitter":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"versions-select":{"type":"branches"},"graph":{},"donate":{"alipay":"https://cai-hello-1253732611.cos.ap-shanghai.myqcloud.com/share/zhifubao-pay.jpg","alipayText":"支付宝打赏","button":"赏","title":"","wechat":"https://cai-hello-1253732611.cos.ap-shanghai.myqcloud.com/share/weixin-pay.jpg","wechatText":"微信打赏"},"katex":{},"fontsettings":{"theme":"white","family":"sans","size":2},"musicxml":{},"sectionx":{"tag":"b"},"mermaid-gb3":{},"anchor-navigation-ex":{"isRewritePageTitle":false,"tocLevel1Icon":"fa fa-hand-o-right","tocLevel2Icon":"fa fa-hand-o-right","tocLevel3Icon":"fa fa-hand-o-right"},"favicon":{"shortcut":"favicon.ico","bookmark":"favicon.ico"},"theme-comscore":{},"prism-themes":{},"alerts":{},"github-buttons":{"repo":"xishengcai/xisheng.blog","types":["star"],"size":"small"},"3-ba":{"configuration":"auto","token":"ff100361cdce95dd4c8fb96b4009f7bc"},"expandable-chapters-small":{},"local-video":{},"klipse":{"myConfigKey":"it's the default value"},"advanced-emoji":{"embedEmojis":false},"include-codeblock":{"check":false,"edit":true,"fixlang":false,"lang":"","template":"ace","theme":"chrome","unindent":true},"sharing":{"qq":false,"all":["facebook","google","twitter","weibo","instapaper","linkedin","pocket","stumbleupon","qq","qzone"],"douban":false,"facebook":false,"weibo":true,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":true,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":true},"terminal":{"copyButtons":true,"fade":false,"style":"flat"},"edit-link":{"label":"Edit This Page","base":"https://github.com/xishengcai/xisheng.blog/edit/master"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":true},"anchors":{},"chart":{"type":"c3"},"toggle-chapters":{},"expandable-chapters":{},"search-plus":{}},"theme":"default","author":"xishengcai","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"这是程序员吗","language":"zh-hans","output.name":"site","links":{"sidebar":{"Home":"https://xisheng.vip"}},"gitbook":"3.2.3","description":"这是程序员吗"},"file":{"path":"blog/kubernetes/controller.md","mtime":"2021-04-09T17:41:29.983Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-06-23T07:51:54.455Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/URI.js/1.16.1/URI.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-disqus/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sectionx/sectionx.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-local-video/video.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-3-ba/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-terminal/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-musicxml/osmd.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-musicxml/musicxml.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-musicxml/promise.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-versions-select/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    <script src="../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>

    </body>
</html>

